Class: Reflection
- Inherits:
-
Object
- Object
- Reflection
- Defined in:
- lib/reflection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(action, number, aggregator) ⇒ Reflection
constructor
Create a reflection.
-
#randomize(args, input_rule_sets) ⇒ Dynamic
Create random values for each argument from control reflections.
-
#reflect(*args) ⇒ Object
Reflect on a method.
-
#serialize ⇒ Hash
Get the results of the reflection.
Constructor Details
#initialize(action, number, aggregator) ⇒ Reflection
Create a reflection.
34 35 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 34 def initialize(action, number, aggregator) @action = action @unique_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
#status ⇒ Object (readonly)
Returns the value of attribute status.
25 26 27 |
# File 'lib/reflection.rb', line 25 def status @status end |
Instance Method Details
#randomize(args, input_rule_sets) ⇒ Dynamic
Create random values for each argument from control reflections.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/reflection.rb', line 80 def randomize(args, input_rule_sets) random_args = [] args.each_with_index do |arg, arg_num| # Get a random rule in the rule set. rules = input_rule_sets[arg_num].rules agg_rule = rules[rules.keys.sample] # Create a random value that follows that rule. random_args << agg_rule.random() end return random_args end |
#reflect(*args) ⇒ Object
Reflect on a method.
Create a shadow action.
68 69 70 |
# File 'lib/reflection.rb', line 68 def reflect(*args) # Implemented by Control and Experiment. end |
#serialize ⇒ Hash
Get the results of the reflection.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/reflection.rb', line 110 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 => @unique_id, :num => @number, :time => @time, :class => @klass, :method => @method, :status => @status, :message => @message, :inputs => nil, :output => nil, } unless @inputs.nil? reflection[:inputs] = [] @inputs.each do || reflection[:inputs] << .serialize() end end unless @output.nil? reflection[:output] = @output.serialize() end return reflection end |