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.



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

def initialize(*args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#resultObject (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

#callObject



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

Returns:

  • (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