class Eco::CLI::Config::Filters
Attributes
core_config[R]
Public Class Methods
new(core_config:)
click to toggle source
# File lib/eco/cli/config/filters.rb, line 8 def initialize(core_config:) @core_config = core_config @filters = {} @description = {} end
Public Instance Methods
add(option, desc = nil)
click to toggle source
@param option [String] the command line option that activates this filter. @param desc [String] description of the filter.
# File lib/eco/cli/config/filters.rb, line 31 def add(option, desc = nil) raise "Missing block to define the filters builder" unless block_given? callback = Proc.new [option].flatten.compact.each do |opt| @filters[opt] = callback @description[opt] = desc end self end
help(msg = nil, refine: nil)
click to toggle source
@return [String] summary of the filters.
# 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].yield_self 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(io:)
click to toggle source
# File lib/eco/cli/config/filters.rb, line 41 def process(io:) raise "You need to override this method in child classes" end