Class: Cuprum::Currying::CurriedCommand
- Inherits:
-
Cuprum::Command
- Object
- Cuprum::Command
- Cuprum::Currying::CurriedCommand
- Defined in:
- lib/cuprum/currying/curried_command.rb
Overview
A CurriedCommand wraps another command and passes preset params to #call.
Instance Attribute Summary collapse
-
#arguments ⇒ Array
readonly
The arguments to pass to the curried command.
-
#block ⇒ Proc?
readonly
A block to pass to the curried command.
-
#command ⇒ Cuprum::Command
readonly
The original command to curry.
-
#keywords ⇒ Hash
readonly
The keywords to pass to the curried command.
Instance Method Summary collapse
-
#call(*args, **kwargs) ⇒ Cuprum::Result
Merges the arguments and keywords and calls the wrapped command.
-
#initialize(command:, arguments: [], block: nil, keywords: {}) { ... } ⇒ CurriedCommand
constructor
A new instance of CurriedCommand.
Methods inherited from Cuprum::Command
Methods included from Steps
Methods included from Cuprum::Currying
Methods included from Processing
Constructor Details
#initialize(command:, arguments: [], block: nil, keywords: {}) { ... } ⇒ CurriedCommand
Returns a new instance of CurriedCommand.
60 61 62 63 64 65 66 67 |
# File 'lib/cuprum/currying/curried_command.rb', line 60 def initialize(command:, arguments: [], block: nil, keywords: {}) super() @arguments = arguments @block = block @command = command @keywords = keywords end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns the arguments to pass to the curried command.
92 93 94 |
# File 'lib/cuprum/currying/curried_command.rb', line 92 def arguments @arguments end |
#block ⇒ Proc? (readonly)
Returns a block to pass to the curried command.
95 96 97 |
# File 'lib/cuprum/currying/curried_command.rb', line 95 def block @block end |
#command ⇒ Cuprum::Command (readonly)
Returns the original command to curry.
98 99 100 |
# File 'lib/cuprum/currying/curried_command.rb', line 98 def command @command end |
#keywords ⇒ Hash (readonly)
Returns the keywords to pass to the curried command.
101 102 103 |
# File 'lib/cuprum/currying/curried_command.rb', line 101 def keywords @keywords end |
Instance Method Details
#call(*args, **kwargs) ⇒ Cuprum::Result
Merges the arguments and keywords and calls the wrapped command.
First, the arguments array is created starting with the :arguments passed to #initialize. Any positional arguments passed directly to #call are then appended.
Second, the keyword arguments are created by merging the keywords passed directly into #call into the keywods passed to #initialize. This means that if a key is passed in both places, the value passed into #call will take precedence.
Finally, the merged arguments and keywords are passed into the original command’s #call method.
|
# File 'lib/cuprum/currying/curried_command.rb', line 69
|