Class: Igniter::Extensions::Contracts::Dataflow::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processed:, aggregates:, inputs:) ⇒ Result

Returns a new instance of Result.



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

def initialize(processed:, aggregates:, inputs:)
  @processed = processed
  @diff = processed.diff
  @aggregates = aggregates.transform_keys(&:to_sym).freeze
  @inputs = inputs
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/igniter/extensions/contracts/dataflow/result.rb', line 43

def method_missing(name, *args)
  return super unless args.empty?
  return processed if name.to_sym == :processed
  return aggregate(name) if aggregates.key?(name.to_sym)

  super
end

Instance Attribute Details

#aggregatesObject (readonly)

Returns the value of attribute aggregates.



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

def aggregates
  @aggregates
end

#diffObject (readonly)

Returns the value of attribute diff.



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

def diff
  @diff
end

#inputsObject (readonly)

Returns the value of attribute inputs.



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

def inputs
  @inputs
end

#processedObject (readonly) Also known as: collection

Returns the value of attribute processed.



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

def processed
  @processed
end

Instance Method Details

#aggregate(name) ⇒ Object



20
21
22
# File 'lib/igniter/extensions/contracts/dataflow/result.rb', line 20

def aggregate(name)
  aggregates.fetch(name.to_sym)
end

#output(name) ⇒ Object



24
25
26
# File 'lib/igniter/extensions/contracts/dataflow/result.rb', line 24

def output(name)
  aggregate(name)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(name, include_private = false)
  name.to_sym == :processed || aggregates.key?(name.to_sym) || super
end

#summaryObject



28
29
30
31
32
33
# File 'lib/igniter/extensions/contracts/dataflow/result.rb', line 28

def summary
  {
    diff: diff.to_h,
    aggregates: aggregates
  }
end

#to_hObject



35
36
37
38
39
40
41
# File 'lib/igniter/extensions/contracts/dataflow/result.rb', line 35

def to_h
  {
    processed: processed.to_h,
    aggregates: aggregates,
    inputs: inputs.to_h
  }
end