Sha256: c570592dac9006694b50be0a322cd0ce5b0ac702015c7983deb50fd69b01e39f

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 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)
          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

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

        private


      end
    end
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eco-helpers-2.0.26 lib/eco/cli/config/filters.rb