Class: Lite::Command::Complex

Inherits:
Object
  • Object
show all
Defined in:
lib/lite/command/complex.rb

Direct Known Subclasses

Procedure

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Complex

Returns a new instance of Complex.



26
27
28
# File 'lib/lite/command/complex.rb', line 26

def initialize(*args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



24
25
26
# File 'lib/lite/command/complex.rb', line 24

def args
  @args
end

#resultObject (readonly)

Returns the value of attribute result.



24
25
26
# File 'lib/lite/command/complex.rb', line 24

def result
  @result
end

Class Method Details

.call(*args) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/lite/command/complex.rb', line 9

def call(*args)
  klass = new(*args)
  raise Lite::Command::NotImplementedError unless klass.respond_to?(:execute)

  klass.call
  klass
end

.execute(*args) ⇒ Object



17
18
19
20
# File 'lib/lite/command/complex.rb', line 17

def execute(*args)
  klass = call(*args)
  klass.result
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
# File 'lib/lite/command/complex.rb', line 30

def call
  raise Lite::Command::NotImplementedError unless defined?(execute)
  return @result if called?

  @called = true
  @result = execute
end

#called?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/lite/command/complex.rb', line 38

def called?
  @called ||= false
end

#recall!Object



42
43
44
45
46
# File 'lib/lite/command/complex.rb', line 42

def recall!
  @called = false
  %i[cache errors].each { |mixin| send(mixin).clear if respond_to?(mixin) }
  call
end