Class: Tabry::Models::FlagsList
Instance Attribute Summary
Attributes inherited from ConfigList
#unflattened
Instance Method Summary
collapse
Methods inherited from ConfigList
#each, #empty?, #flatten, #length, #to_a
Constructor Details
#initialize(**args) ⇒ FlagsList
Returns a new instance of FlagsList.
9
10
11
|
# File 'lib/tabry/models/flags_list.rb', line 9
def initialize(**args)
super(**args, klass: Flag)
end
|
Instance Method Details
#[](flag_name) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/tabry/models/flags_list.rb', line 38
def [](flag_name)
if flag_name.is_a?(Integer)
to_a[flag_name]
else
to_a.find { |f| f.name == flag_name }
end
end
|
#first_required_flag(used:) ⇒ Object
13
14
15
16
17
|
# File 'lib/tabry/models/flags_list.rb', line 13
def first_required_flag(used:)
to_a.find do |flag|
flag.required && !used[flag.name]
end
end
|
#match(token) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/tabry/models/flags_list.rb', line 27
def match(token)
to_a.each do |flag|
if (arg_value = flag.match_with_value(token))
return flag, arg_value
elsif flag.match(token)
return flag
end
end
false
end
|
#options(token, used:) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/tabry/models/flags_list.rb', line 19
def options(token, used:)
to_a.map do |flag|
if token&.start_with?("-") && flag.name_with_dashes.start_with?(token) && !used[flag.name]
flag.name_with_dashes
end
end.compact
end
|