Class: BaseOptArg

Inherits:
Object
  • Object
show all
Defined in:
lib/yaggo/dsl.rb

Direct Known Subclasses

Arg, Option

Instance Method Summary collapse

Instance Method Details

#access=(types) ⇒ Object



126
127
128
129
130
# File 'lib/yaggo/dsl.rb', line 126

def access=(types)
  types.all? { |t| ["read", "write", "exec"].include?(t) } or
    raise "Invalid access type(s): #{types.join(", ")}"
  @access_types = types
end

#at_least=(n) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/yaggo/dsl.rb', line 96

def at_least=(n)
  multiple = true
  nb = case n
       when Integer
         n
       when String
         n =~ /^\d+$/ ? n.to_i : nil
       else
         nil
       end
  raise "Invalid minimum number for at_least (#{n})" if nb.nil?
  self.multiple = true
  @at_least = nb
end

#checkObject



132
133
134
135
136
# File 'lib/yaggo/dsl.rb', line 132

def check
  if !@access_types.empty? && @type != :c_string
    raise "Access checking is valid only with a path (a c_string)"
  end
end

#suffix=(t) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/yaggo/dsl.rb', line 116

def suffix=(t)
  case type
  when nil
    raise "A numerical type must be specify before suffix"
  when :flag, :string, :c_string
    raise "Suffix is meaningless with the type #{type}"
  end
  @suffix = t
end

#type=(t) ⇒ Object



111
112
113
114
# File 'lib/yaggo/dsl.rb', line 111

def type=(t)
  raise "More than 1 type specified: '#{type}' and '#{t}'" unless @type.nil? || @type == t
  @type = t
end