Sha256: f7d0771b44417d314c2bd6618fe31f5cbebd6429a38b497e96d5be59a229fb07

Contents?: true

Size: 1.19 KB

Versions: 167

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)
          unless io && io.is_a?(Eco::API::UseCases::BaseIO)
            raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
          end

          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

167 entries across 167 versions & 1 rubygems

Version Path
eco-helpers-2.5.10 lib/eco/cli/config/input.rb
eco-helpers-2.5.9 lib/eco/cli/config/input.rb
eco-helpers-2.5.8 lib/eco/cli/config/input.rb
eco-helpers-2.5.7 lib/eco/cli/config/input.rb
eco-helpers-2.5.6 lib/eco/cli/config/input.rb
eco-helpers-2.5.5 lib/eco/cli/config/input.rb
eco-helpers-2.5.4 lib/eco/cli/config/input.rb
eco-helpers-2.5.3 lib/eco/cli/config/input.rb
eco-helpers-2.5.2 lib/eco/cli/config/input.rb
eco-helpers-2.5.1 lib/eco/cli/config/input.rb
eco-helpers-2.4.9 lib/eco/cli/config/input.rb
eco-helpers-2.4.8 lib/eco/cli/config/input.rb
eco-helpers-2.4.7 lib/eco/cli/config/input.rb
eco-helpers-2.4.6 lib/eco/cli/config/input.rb
eco-helpers-2.4.5 lib/eco/cli/config/input.rb
eco-helpers-2.4.4 lib/eco/cli/config/input.rb
eco-helpers-2.4.3 lib/eco/cli/config/input.rb
eco-helpers-2.4.2 lib/eco/cli/config/input.rb
eco-helpers-2.3.3 lib/eco/cli/config/input.rb
eco-helpers-2.3.2 lib/eco/cli/config/input.rb