Class: Reflekt::Reflection

Inherits:
Object
  • Object
show all
Includes:
LitCLI
Defined in:
lib/reflection.rb

Direct Known Subclasses

Control, Experiment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, number, aggregator) ⇒ Reflection

Create a reflection.

Parameters:

  • action (Action)

    The Action that created this Reflection.

  • number (Integer)

    Multiple Reflections can be created per Action.

  • aggregator (RuleSetAggregator)

    The aggregated RuleSet for this class/method.


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/reflection.rb', line 36

def initialize(action, number, aggregator)
  @action = action
  @reflection_id = action.unique_id + number
  @number = number

  # Dependency.
  @aggregator = aggregator

  # Caller.
  @klass = action.klass
  @method = action.method

  # Metadata.
  @inputs = nil
  @output = nil

  # Clone the action's calling object.
  # TODO: Abstract away into Clone class.
  @clone = action.caller_object.clone

  # Result.
  @status = :pass
  @time = Time.now.to_i
  @message = nil
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status


27
28
29
# File 'lib/reflection.rb', line 27

def status
  @status
end

Instance Method Details

#reflect(*args) ⇒ Object

Reflect on a method.

Create a shadow action.

Parameters:

  • *args (Dynamic)

    The method's arguments.


68
69
70
# File 'lib/reflection.rb', line 68

def reflect(*args)
  # Implemented by Control and Experiment.
end

#serializeHash

Get the results of the reflection.

Returns:

  • (Hash)

    Reflection metadata.


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/reflection.rb', line 83

def serialize()
  # Create execution ID from the ID of the first action in   the ActionStack.
  execution_id = @action.unique_id
  unless @action.base.nil?
    execution_id = @action.base.unique_id
  end

  # Build reflection.
  reflection = {
    :eid => execution_id,
    :aid => @action.unique_id,
    :rid => @reflection_id,
    :num => @number,
    :time => @time,
    :class => @klass,
    :method => @method,
    :status => @status,
    :message => @message,
    :inputs => nil,
    :output => nil,
  }

  # TODO: After the last experiment for an action is completed, serialize()
  #       appears to be called twice. Possibly due to inheritance.
  🔥"> Save meta for #{@method}()", :save, :meta, @klass

  unless @inputs.nil?
    reflection[:inputs] = []
    @inputs.each do |meta|
      meta.nil? ? nil : reflection[:inputs] << meta.serialize()
    end
  end

  unless @output.nil?
    reflection[:output] = @output.serialize()
  end

  return reflection
end