Class: Tabry::Models::Flag

Inherits:
ConfigObject show all
Defined in:
lib/tabry/models/flag.rb

Constant Summary collapse

FIELDS =
{
  aliases: :string_array,
  description: :string,
  name: :string, # TODO: required
  required: :boolean,
  arg: :boolean,
  options: [:list_object, :OptionsList]
}.freeze

Instance Attribute Summary

Attributes inherited from ConfigObject

#_raw, #_root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ConfigObject

as_json, #as_json, #assert_of_class, #init_field_boolean, #init_field_list_object, #init_field_object, #init_field_string, #init_field_string_array, #initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Tabry::Models::ConfigObject

Class Method Details

.new(**args) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/tabry/models/flag.rb', line 10

def self.new(**args)
  if args[:raw]["include"]
    IncludeFlag.new(**args)
  else
    super(**args)
  end
end

Instance Method Details

#alias_with_dash(ali) ⇒ Object



48
49
50
# File 'lib/tabry/models/flag.rb', line 48

def alias_with_dash(ali)
  (ali.length == 1) ? "-#{ali}" : "--#{ali}"
end

#flattenObject



27
28
29
# File 'lib/tabry/models/flag.rb', line 27

def flatten
  self
end

#match(token) ⇒ Object



40
41
42
# File 'lib/tabry/models/flag.rb', line 40

def match(token)
  [name, *aliases].any? { |al| token == alias_with_dash(al) }
end

#match_with_value(token) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/tabry/models/flag.rb', line 31

def match_with_value(token)
  [name, *aliases].each do |al|
    if al.length > 1 && token.start_with?("--#{al}=")
      return token.sub("--#{al}=", "")
    end
  end
  nil
end

#name_with_dashesObject



44
45
46
# File 'lib/tabry/models/flag.rb', line 44

def name_with_dashes
  @name_with_dashes ||= alias_with_dash(name)
end