Class: ShellOpts::Grammar::FileArgument

Inherits:
ArgumentType show all
Defined in:
lib/shellopts/argument_type.rb

Instance Attribute Summary collapse

Attributes inherited from ArgumentType

#message

Instance Method Summary collapse

Methods inherited from ArgumentType

#convert, #name, #to_s

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

#kindObject (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

Returns:

  • (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

Returns:

  • (Boolean)


86
# File 'lib/shellopts/argument_type.rb', line 86

def value?(value) value.is_a?(String) end