Class: BranchIOCLI::Configuration::OptionWrapper
- Inherits:
-
Object
- Object
- BranchIOCLI::Configuration::OptionWrapper
- Defined in:
- lib/branch_io_cli/configuration/option_wrapper.rb
Overview
Proxy class for use with Command.new.
Instance Attribute Summary collapse
-
#add_defaults ⇒ Object
readonly
Returns the value of attribute add_defaults.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #build_option_hash ⇒ Object
-
#initialize(hash, options, add_defaults = true) ⇒ OptionWrapper
constructor
A new instance of OptionWrapper.
- #method_missing(method_sym, *arguments, &block) ⇒ Object
Constructor Details
#initialize(hash, options, add_defaults = true) ⇒ OptionWrapper
Returns a new instance of OptionWrapper.
9 10 11 12 13 14 15 16 17 |
# File 'lib/branch_io_cli/configuration/option_wrapper.rb', line 9 def initialize(hash, , add_defaults = true) hash ||= {} @hash = hash @options = @add_defaults = add_defaults build_option_hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/branch_io_cli/configuration/option_wrapper.rb', line 19 def method_missing(method_sym, *arguments, &block) option = @option_hash[method_sym] return super unless option value = hash[method_sym] return value unless add_defaults && value.nil? default_value = option.env_value default_value = option.default_value if default_value.nil? default_value end |
Instance Attribute Details
#add_defaults ⇒ Object (readonly)
Returns the value of attribute add_defaults.
7 8 9 |
# File 'lib/branch_io_cli/configuration/option_wrapper.rb', line 7 def add_defaults @add_defaults end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
5 6 7 |
# File 'lib/branch_io_cli/configuration/option_wrapper.rb', line 5 def hash @hash end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/branch_io_cli/configuration/option_wrapper.rb', line 6 def @options end |
Instance Method Details
#build_option_hash ⇒ Object
31 32 33 |
# File 'lib/branch_io_cli/configuration/option_wrapper.rb', line 31 def build_option_hash @option_hash = .inject({}) { |hash, o| hash.merge o.name => o } end |