Class: Eco::CLI::Config::Input
Instance Attribute Summary collapse
-
#core_config ⇒ Object
readonly
Returns the value of attribute core_config.
-
#default_option ⇒ Object
readonly
Returns the value of attribute default_option.
Instance Method Summary collapse
- #default_option? ⇒ Boolean
- #define(option: nil, &block) ⇒ Object
- #get(io:, option: nil) ⇒ Object
-
#initialize(core_config:, default_option: nil) ⇒ Input
constructor
A new instance of Input.
Constructor Details
#initialize(core_config:, default_option: nil) ⇒ Input
Returns a new instance of Input.
8 9 10 11 12 |
# File 'lib/eco/cli/config/input.rb', line 8 def initialize(core_config:, default_option: nil) @core_config = core_config @default_option = default_option @callbacks = {} end |
Instance Attribute Details
#core_config ⇒ Object (readonly)
Returns the value of attribute core_config.
5 6 7 |
# File 'lib/eco/cli/config/input.rb', line 5 def core_config @core_config end |
#default_option ⇒ Object (readonly)
Returns the value of attribute default_option.
6 7 8 |
# File 'lib/eco/cli/config/input.rb', line 6 def default_option @default_option end |
Instance Method Details
#default_option? ⇒ Boolean
14 15 16 |
# File 'lib/eco/cli/config/input.rb', line 14 def default_option? !!default_option end |
#define(option: nil, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/eco/cli/config/input.rb', line 18 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 |
#get(io:, option: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eco/cli/config/input.rb', line 26 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.) end |