Class: Lite::Command::Complex
- Inherits:
-
Object
- Object
- Lite::Command::Complex
- Defined in:
- lib/lite/command/complex.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #called? ⇒ Boolean
-
#initialize(*args) ⇒ Complex
constructor
A new instance of Complex.
- #recall! ⇒ Object
Constructor Details
#initialize(*args) ⇒ Complex
Returns a new instance of Complex.
27 28 29 |
# File 'lib/lite/command/complex.rb', line 27 def initialize(*args) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
25 26 27 |
# File 'lib/lite/command/complex.rb', line 25 def args @args end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
25 26 27 |
# File 'lib/lite/command/complex.rb', line 25 def result @result end |
Class Method Details
.call(*args, **kwargs, &block) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/lite/command/complex.rb', line 9 def call(*args, **kwargs, &block) instance = new(*args, **kwargs, &block) raise Lite::Command::NotImplementedError unless instance.respond_to?(:execute) instance.call instance end |
.execute(*args, **kwargs, &block) ⇒ Object
18 19 20 21 |
# File 'lib/lite/command/complex.rb', line 18 def execute(*args, **kwargs, &block) instance = call(*args, **kwargs, &block) instance.result end |
Instance Method Details
#call ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/lite/command/complex.rb', line 31 def call raise Lite::Command::NotImplementedError unless defined?(execute) return @result if called? @called = true @result = execute end |
#called? ⇒ Boolean
40 41 42 |
# File 'lib/lite/command/complex.rb', line 40 def called? @called ||= false end |
#recall! ⇒ Object
44 45 46 47 48 |
# File 'lib/lite/command/complex.rb', line 44 def recall! @called = false %i[cache errors].each { |method_name| send(method_name).clear if respond_to?(method_name) } call end |