Class: Eco::CLI::Config::Filters
- Includes:
- Help
- Defined in:
- lib/eco/cli/config/filters.rb,
lib/eco/cli/config/filters/input_filters.rb,
lib/eco/cli/config/filters/people_filters.rb
Direct Known Subclasses
Defined Under Namespace
Classes: InputFilters, PeopleFilters
Instance Attribute Summary collapse
-
#core_config ⇒ Object
readonly
Returns the value of attribute core_config.
Instance Method Summary collapse
- #add(option, desc = nil, &block) ⇒ Object
- #available(keys: false) ⇒ Object
-
#help(msg = nil, refine: nil) ⇒ String
Summary of the filters.
-
#initialize(core_config:) ⇒ Filters
constructor
A new instance of Filters.
- #process ⇒ Object
Constructor Details
#initialize(core_config:) ⇒ Filters
Returns a new instance of Filters.
8 9 10 11 12 |
# File 'lib/eco/cli/config/filters.rb', line 8 def initialize(core_config:) @core_config = core_config @filters = {} @description = {} end |
Instance Attribute Details
#core_config ⇒ Object (readonly)
Returns the value of attribute core_config.
6 7 8 |
# File 'lib/eco/cli/config/filters.rb', line 6 def core_config @core_config end |
Instance Method Details
#add(option, desc = nil, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/eco/cli/config/filters.rb', line 40 def add(option, desc = nil, &block) raise ArgumentError, "Missing block to define the filters builder" unless block_given? callback = block [option].flatten.compact.each do |opt| @filters[opt] = callback @description[opt] = desc end self end |
#available(keys: false) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/eco/cli/config/filters.rb', line 30 def available(keys: false) return @filters.keys if keys @filters.keys.map do |key| [key, @filters[key], @description[key]] end end |
#help(msg = nil, refine: nil) ⇒ String
Returns summary of the filters.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/eco/cli/config/filters.rb', line 15 def help(msg = nil, refine: nil) refinement = refine.is_a?(String)? " (containing: '#{refine}')" : "" msg ||= "The following are the available filters#{refinement}:" [msg].then do |lines| max_len = keys_max_len(@filters.keys) @filters.keys.sort.select do |key| !refine.is_a?(String) || key.include?(refine) end.each do |key| lines << help_line(key, @description[key], max_len) end lines end.join("\n") end |
#process ⇒ Object
51 52 53 |
# File 'lib/eco/cli/config/filters.rb', line 51 def process(*) raise "You need to override this method in child classes" end |