Sha256: 1c196ef1da836a27dd15df45731729281459e68d23a9163475c12680148bea4b

Contents?: true

Size: 1.19 KB

Versions: 31

Compression:

Stored size: 1.19 KB

Contents

module Eco
  class CLI
    class Config
      class Input
        attr_reader :core_config
        attr_reader :default_option

        def initialize(core_config:, default_option: nil)
          @core_config    = core_config
          @default_option = default_option
          @callbacks      = {}
        end

        def default_option?
          !!default_option
        end

        def define(option: nil, &block)
          option ||= default_option
          raise "Missing option to identify the input (no default defined)" unless !!option
          raise "Missing block to define the input obtention process" unless block

          @callbacks[option] = block
        end

        def get(io:, option: nil)
          msg = "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
          raise ArgumentError, msg unless io.is_a?(Eco::API::UseCases::BaseIO)

          option ||= default_option
          raise "Missing option to identify the input (no default defined)" unless option

          callback = @callbacks[option] || @callbacks[default_option]
          callback.call(io.session, option, io.options)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/cli/config/input.rb
eco-helpers-3.0.20 lib/eco/cli/config/input.rb
eco-helpers-3.0.19 lib/eco/cli/config/input.rb
eco-helpers-3.0.18 lib/eco/cli/config/input.rb
eco-helpers-3.0.17 lib/eco/cli/config/input.rb
eco-helpers-3.0.16 lib/eco/cli/config/input.rb
eco-helpers-3.0.15 lib/eco/cli/config/input.rb
eco-helpers-3.0.14 lib/eco/cli/config/input.rb
eco-helpers-3.0.13 lib/eco/cli/config/input.rb
eco-helpers-3.0.12 lib/eco/cli/config/input.rb
eco-helpers-3.0.11 lib/eco/cli/config/input.rb
eco-helpers-3.0.10 lib/eco/cli/config/input.rb
eco-helpers-3.0.9 lib/eco/cli/config/input.rb
eco-helpers-3.0.8 lib/eco/cli/config/input.rb
eco-helpers-3.0.7 lib/eco/cli/config/input.rb
eco-helpers-3.0.6 lib/eco/cli/config/input.rb
eco-helpers-3.0.5 lib/eco/cli/config/input.rb
eco-helpers-3.0.4 lib/eco/cli/config/input.rb
eco-helpers-3.0.3 lib/eco/cli/config/input.rb
eco-helpers-3.0.2 lib/eco/cli/config/input.rb