Class: ShellOpts::Grammar::FileArgument
- Inherits:
-
ArgumentType
- Object
- ArgumentType
- ShellOpts::Grammar::FileArgument
- Defined in:
- lib/shellopts/argument_type.rb
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Attributes inherited from ArgumentType
Instance Method Summary collapse
-
#initialize(kind) ⇒ FileArgument
constructor
A new instance of FileArgument.
- #match?(name, literal) ⇒ Boolean
-
#value?(value) ⇒ Boolean
Note: No checks done, not sure if it is a feature or a bug.
Methods inherited from ArgumentType
Constructor Details
#initialize(kind) ⇒ FileArgument
Returns a new instance of FileArgument.
62 63 64 65 |
# File 'lib/shellopts/argument_type.rb', line 62 def initialize(kind) constrain kind, :file, :dir, :path, :efile, :edir, :epath, :nfile, :ndir, :npath @kind = kind end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
60 61 62 |
# File 'lib/shellopts/argument_type.rb', line 60 def kind @kind end |
Instance Method Details
#match?(name, literal) ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/shellopts/argument_type.rb', line 67 def match?(name, literal) case kind when :file; match_path(name, literal, kind, :file?, :default) when :dir; match_path(name, literal, kind, :directory?, :default) when :path; match_path(name, literal, kind, :exist?, :default) when :efile; match_path(name, literal, kind, :file?, :exist) when :edir; match_path(name, literal, kind, :directory?, :exist) when :epath; match_path(name, literal, kind, :exist?, :exist) when :nfile; match_path(name, literal, kind, :file?, :new) when :ndir; match_path(name, literal, kind, :directory?, :new) when :npath; match_path(name, literal, kind, :exist?, :new) else raise InternalError, "Illegal kind: #{kind.inspect}" end end |
#value?(value) ⇒ Boolean
Note: No checks done, not sure if it is a feature or a bug
86 |
# File 'lib/shellopts/argument_type.rb', line 86 def value?(value) value.is_a?(String) end |