Class: FunctionalLightService::Sequencer::Sequencer

Inherits:
Object
  • Object
show all
Defined in:
lib/functional-light-service/functional/sequencer.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ Sequencer

Returns a new instance of Sequencer.



36
37
38
39
# File 'lib/functional-light-service/functional/sequencer.rb', line 36

def initialize(instance)
  @operations = []
  @operation_wrapper = OperationWrapper.new(instance)
end

Instance Method Details

#and_then(&block) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/functional-light-service/functional/sequencer.rb', line 55

def and_then(&block)
  raise ArgumentError, 'no block given' unless block_given?
  raise InvalidSequenceError, 'and_yield already called' if @sequenced_operations

  @operations << Operation::AndThen.new(block)
end

#and_yield(&block) ⇒ Object

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
# File 'lib/functional-light-service/functional/sequencer.rb', line 69

def and_yield(&block)
  raise ArgumentError, 'no block given' unless block_given?
  raise InvalidSequenceError, 'and_yield already called' if @sequenced_operations

  @operations << Operation::AndYield.new(block)

  prepare_sequenced_operations
end

#get(name, &block) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
# File 'lib/functional-light-service/functional/sequencer.rb', line 41

def get(name, &block)
  raise ArgumentError, 'no block given' unless block_given?
  raise InvalidSequenceError, 'and_yield already called' if @sequenced_operations

  @operations << Operation::Get.new(block, name)
end

#let(name, &block) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
52
53
# File 'lib/functional-light-service/functional/sequencer.rb', line 48

def let(name, &block)
  raise ArgumentError, 'no block given' unless block_given?
  raise InvalidSequenceError, 'and_yield already called' if @sequenced_operations

  @operations << Operation::Let.new(block, name)
end

#observe(&block) ⇒ Object

Raises:

  • (ArgumentError)


62
63
64
65
66
67
# File 'lib/functional-light-service/functional/sequencer.rb', line 62

def observe(&block)
  raise ArgumentError, 'no block given' unless block_given?
  raise InvalidSequenceError, 'and_yield already called' if @sequenced_operations

  @operations << Operation::Observe.new(block)
end

#yieldObject



78
79
80
81
82
# File 'lib/functional-light-service/functional/sequencer.rb', line 78

def yield
  raise InvalidSequenceError, 'and_yield not called' unless @sequenced_operations

  @operation_wrapper.instance_eval(&@sequenced_operations)
end