Sha256: f6519a6f16f3ddede1241d2bfcbe8a83f5be91c74df1119b5450d2b98d6e2309

Contents?: true

Size: 1.58 KB

Versions: 14

Compression:

Stored size: 1.58 KB

Contents

module Eco
  class CLI
    class Config
      class Filters
        include Eco::CLI::Config::Help
        attr_reader :core_config

        def initialize(core_config:)
          @core_config = core_config
          @filters     = {}
          @description = {}
        end

        # @return [String] summary of the filters.
        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

        # @param option [String] the command line option that activates this filter.
        # @param desc [String] description of the filter.
        def add(option, desc = nil, &block)
          raise "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

        def process(io:)
          raise "You need to override this method in child classes"
        end
      end
    end
  end
end

require_relative 'filters/people_filters'
require_relative 'filters/input_filters'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
eco-helpers-2.7.16 lib/eco/cli/config/filters.rb
eco-helpers-2.7.15 lib/eco/cli/config/filters.rb
eco-helpers-2.7.14 lib/eco/cli/config/filters.rb
eco-helpers-2.7.13 lib/eco/cli/config/filters.rb
eco-helpers-2.7.12 lib/eco/cli/config/filters.rb
eco-helpers-2.7.4 lib/eco/cli/config/filters.rb
eco-helpers-2.7.2 lib/eco/cli/config/filters.rb
eco-helpers-2.7.1 lib/eco/cli/config/filters.rb
eco-helpers-2.7.0 lib/eco/cli/config/filters.rb
eco-helpers-2.6.4 lib/eco/cli/config/filters.rb
eco-helpers-2.6.3 lib/eco/cli/config/filters.rb
eco-helpers-2.6.2 lib/eco/cli/config/filters.rb
eco-helpers-2.6.1 lib/eco/cli/config/filters.rb
eco-helpers-2.6.0 lib/eco/cli/config/filters.rb