Class: DSLCompose::Reader::ExecutionReader::ArgumentsReader
- Inherits:
-
Object
- Object
- DSLCompose::Reader::ExecutionReader::ArgumentsReader
- Defined in:
- lib/dsl_compose/reader/execution_reader/arguments_reader.rb
Overview
This class is part of a decorator for DSL executions.
Instance Method Summary collapse
-
#has_argument?(argument_name) ⇒ Boolean
returns true if the DSL has an argument with the provided name.
-
#initialize(arguments, argument_values) ⇒ ArgumentsReader
constructor
When instantiated, this class dynamically provides methods which corespiond to argument names and returns the argument value.
-
#method_missing(method_name) ⇒ Object
catch and process any method calls, if arguments exist with the same name as the method call, then return the appropriate value, otherwise raise an error.
- #respond_to_missing?(method_name) ⇒ Boolean
Constructor Details
#initialize(arguments, argument_values) ⇒ ArgumentsReader
When instantiated, this class dynamically provides methods which corespiond to argument names and returns the argument value.
‘arguments` should be the DSL Arguments object, as this represents the possible arguments `argument_values` is a key/value object representing the actual values which were provided when the DSL was executed
This class is used to represent both DSL arguments, and dsl_method arguments
16 17 18 19 |
# File 'lib/dsl_compose/reader/execution_reader/arguments_reader.rb', line 16 def initialize arguments, argument_values @arguments = arguments @argument_values = argument_values end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
catch and process any method calls, if arguments exist with the same name as the method call, then return the appropriate value, otherwise raise an error
23 24 25 26 27 28 |
# File 'lib/dsl_compose/reader/execution_reader/arguments_reader.rb', line 23 def method_missing method_name # fetch the argument to ensure it exists (this will raise an error if it does not) argument = @arguments.argument method_name # return the argument value, or nil if the argument was not used @argument_values.arguments[argument.name] end |
Instance Method Details
#has_argument?(argument_name) ⇒ Boolean
returns true if the DSL has an argument with the provided name
31 32 33 |
# File 'lib/dsl_compose/reader/execution_reader/arguments_reader.rb', line 31 def has_argument? argument_name @arguments.has_argument? argument_name end |
#respond_to_missing?(method_name) ⇒ Boolean
35 36 37 |
# File 'lib/dsl_compose/reader/execution_reader/arguments_reader.rb', line 35 def respond_to_missing? method_name @arguments.has_argument? method_name end |