Skip to content

Commit

Permalink
Remove Path::Kind::NATIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Dec 4, 2018
1 parent 38081d6 commit 14b0a61
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ struct Path
end

enum Kind : UInt8
# TODO: Consider adding NATIVE member, see https://github.com/crystal-lang/crystal/pull/5635#issuecomment-441237811

POSIX
WINDOWS
NATIVE

def self.native : Kind
{% if flag?(:win32) %}
Expand All @@ -73,24 +74,15 @@ struct Path
POSIX
{% end %}
end

# :nodoc:
def self.resolve_native(kind : Kind) : Kind
if kind == NATIVE
native
else
kind
end
end
end

# The file/directory separator characters of the current platform.
# `{'/'}` on POSIX, `{'\\', '/'}` on Windows.
SEPARATORS = separators(Kind::NATIVE)
SEPARATORS = separators(Kind.native)

# :nodoc:
def self.separators(kind)
if Kind.resolve_native(kind) == Kind::WINDOWS
if kind.windows?
{'\\', '/'}
else
{'/'}
Expand All @@ -102,7 +94,7 @@ struct Path
# When compiling for a windows target, this is equal to `Path.windows()`,
# otherwise `Path.posix` is used.
def self.new(name : String = "") : Path
new(name.check_no_null_byte, Kind::NATIVE)
new(name.check_no_null_byte, Kind.native)
end

# ditto
Expand Down Expand Up @@ -166,17 +158,17 @@ struct Path

# Returns `true` if this is a Windows path.
def windows? : Bool
Kind.resolve_native(@kind).windows?
@kind.windows?
end

# Returns `true` if this is a POSIX path.
def posix? : Bool
Kind.resolve_native(@kind).posix?
@kind.posix?
end

# Returns `true` if this is a native path for the target platform.
def native? : Bool
Kind.resolve_native(@kind) == Kind.native
@kind == Kind.native
end

# Returns all components of this path except the last one.
Expand Down Expand Up @@ -541,7 +533,7 @@ struct Path
#
# See `#to_windows` and `#to_posix` for details.
def to_kind(kind)
if Kind.resolve_native(kind).posix?
if kind.posix?
to_posix
else
to_windows
Expand Down Expand Up @@ -921,7 +913,7 @@ struct Path

# Inspects this path to *io*.
def inspect(io : IO)
if @kind == Kind::NATIVE
if native?
io << "Path["
@name.inspect(io)
io << ']'
Expand Down

0 comments on commit 14b0a61

Please sign in to comment.