Class: Igniter::Extensions::Contracts::Dataflow::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/extensions/contracts/dataflow/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, key:, window: nil, context: []) ⇒ Builder

Returns a new instance of Builder.



10
11
12
13
14
15
16
17
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 10

def initialize(source:, key:, window: nil, context: [])
  @source = source.to_sym
  @key = key.to_sym
  @window = window
  @context = Array(context).map(&:to_sym).freeze
  @item_block = nil
  @aggregate_operators = {}
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 8

def context
  @context
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 8

def key
  @key
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 8

def source
  @source
end

#windowObject (readonly)

Returns the value of attribute window.



8
9
10
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 8

def window
  @window
end

Instance Method Details

#aggregate(name, initial:, add:, remove:) ⇒ Object



47
48
49
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 47

def aggregate(name, initial:, add:, remove:)
  register(name, AggregateOperators.custom(initial: initial, add: add, remove: remove))
end

#avg(name, using:) ⇒ Object



31
32
33
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 31

def avg(name, using:)
  register(name, AggregateOperators.avg(projection: using))
end

#build!(environment) ⇒ Object

Raises:

  • (Igniter::Contracts::Error)


51
52
53
54
55
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 51

def build!(environment)
  raise Igniter::Contracts::Error, "DataflowPack requires an `item do ... end` definition" unless @item_block

  [environment.compile(&@item_block), @aggregate_operators.dup.freeze]
end

#count(name, matching: nil) ⇒ Object



23
24
25
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 23

def count(name, matching: nil)
  register(name, AggregateOperators.count(filter: matching))
end

#group_count(name, using:) ⇒ Object



43
44
45
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 43

def group_count(name, using:)
  register(name, AggregateOperators.group_count(projection: using))
end

#item(&block) ⇒ Object



19
20
21
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 19

def item(&block)
  @item_block = block
end

#max(name, using:) ⇒ Object



39
40
41
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 39

def max(name, using:)
  register(name, AggregateOperators.max(projection: using))
end

#min(name, using:) ⇒ Object



35
36
37
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 35

def min(name, using:)
  register(name, AggregateOperators.min(projection: using))
end

#sum(name, using:) ⇒ Object



27
28
29
# File 'lib/igniter/extensions/contracts/dataflow/builder.rb', line 27

def sum(name, using:)
  register(name, AggregateOperators.sum(projection: using))
end