Class: Reflekt::Action
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#caller_class ⇒ Object
Returns the value of attribute caller_class.
-
#caller_id ⇒ Object
Returns the value of attribute caller_id.
-
#caller_object ⇒ Object
Returns the value of attribute caller_object.
-
#child ⇒ Object
Returns the value of attribute child.
-
#control ⇒ Object
Returns the value of attribute control.
-
#experiments ⇒ Object
Returns the value of attribute experiments.
-
#is_actioned ⇒ Object
Returns the value of attribute is_actioned.
-
#is_base ⇒ Object
Returns the value of attribute is_base.
-
#is_reflecting ⇒ Object
Returns the value of attribute is_reflecting.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#method ⇒ Object
Returns the value of attribute method.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#unique_id ⇒ Object
Returns the value of attribute unique_id.
Instance Method Summary collapse
- #has_empty_experiments? ⇒ Boolean
- #has_finished_loop? ⇒ Boolean
-
#initialize(caller_object, method, config, db, stack, aggregator) ⇒ Action
constructor
Create Action.
- #is_actioned? ⇒ Boolean
-
#is_reflecting? ⇒ Boolean
Is the action currently reflecting methods?.
- #reflect(*args) ⇒ Object
Constructor Details
#initialize(caller_object, method, config, db, stack, aggregator) ⇒ Action
Create Action.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/action.rb', line 37 def initialize(caller_object, method, config, db, stack, aggregator) @time = Time.now.to_i @unique_id = @time + rand(1..99999) @base = nil @child = nil @parent = nil # Dependencies. @db = db @stack = stack @aggregator = aggregator # Caller. @caller_object = caller_object @caller_class = caller_object.class @caller_id = caller_object.object_id @klass = @caller_class.to_s.to_sym @method = method # Reflections. @control = nil @experiments = Array.new(config.reflect_amount) # State. @is_reflecting = false if @stack.peek() == nil @is_base = true else @is_base = false @base = @stack.base() end end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
20 21 22 |
# File 'lib/action.rb', line 20 def base @base end |
#caller_class ⇒ Object
Returns the value of attribute caller_class.
17 18 19 |
# File 'lib/action.rb', line 17 def caller_class @caller_class end |
#caller_id ⇒ Object
Returns the value of attribute caller_id.
16 17 18 |
# File 'lib/action.rb', line 16 def caller_id @caller_id end |
#caller_object ⇒ Object
Returns the value of attribute caller_object.
15 16 17 |
# File 'lib/action.rb', line 15 def caller_object @caller_object end |
#child ⇒ Object
Returns the value of attribute child.
22 23 24 |
# File 'lib/action.rb', line 22 def child @child end |
#control ⇒ Object
Returns the value of attribute control.
23 24 25 |
# File 'lib/action.rb', line 23 def control @control end |
#experiments ⇒ Object
Returns the value of attribute experiments.
24 25 26 |
# File 'lib/action.rb', line 24 def experiments @experiments end |
#is_actioned ⇒ Object
Returns the value of attribute is_actioned.
25 26 27 |
# File 'lib/action.rb', line 25 def is_actioned @is_actioned end |
#is_base ⇒ Object
Returns the value of attribute is_base.
27 28 29 |
# File 'lib/action.rb', line 27 def is_base @is_base end |
#is_reflecting ⇒ Object
Returns the value of attribute is_reflecting.
26 27 28 |
# File 'lib/action.rb', line 26 def is_reflecting @is_reflecting end |
#klass ⇒ Object
Returns the value of attribute klass.
18 19 20 |
# File 'lib/action.rb', line 18 def klass @klass end |
#method ⇒ Object
Returns the value of attribute method.
19 20 21 |
# File 'lib/action.rb', line 19 def method @method end |
#parent ⇒ Object
Returns the value of attribute parent.
21 22 23 |
# File 'lib/action.rb', line 21 def parent @parent end |
#unique_id ⇒ Object
Returns the value of attribute unique_id.
14 15 16 |
# File 'lib/action.rb', line 14 def unique_id @unique_id end |
Instance Method Details
#has_empty_experiments? ⇒ Boolean
115 116 117 |
# File 'lib/action.rb', line 115 def has_empty_experiments? @experiments.include? nil end |
#has_finished_loop? ⇒ Boolean
119 120 121 122 123 124 125 |
# File 'lib/action.rb', line 119 def has_finished_loop? return false if is_actioned? == false return false if is_reflecting? return false if has_empty_experiments? true end |
#is_actioned? ⇒ Boolean
106 107 108 |
# File 'lib/action.rb', line 106 def is_actioned? @is_actioned end |
#is_reflecting? ⇒ Boolean
Is the action currently reflecting methods?
111 112 113 |
# File 'lib/action.rb', line 111 def is_reflecting? @is_reflecting end |
#reflect(*args) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/action.rb', line 70 def reflect(*args) 🔥"^ Create control for #{@method}()", :info, :control, @klass @control = Control.new(self, 0, @aggregator) @control.reflect(*args) 🔥"> Reflected control for #{@method}(): #{args}", @control.status, :result, @klass # Stop reflecting when control fails to execute. unless @control.status == :error # Save control. @db.get("controls").push(@control.serialize()) @db.get("reflections").push(@control.serialize()) # Multiple experiments per action. @experiments.each_with_index do |value, index| 🔥"^ Create experiment ##{index + 1} for #{@method}()", :info, :experiment, @klass experiment = Experiment.new(self, index + 1, @aggregator) @experiments[index] = experiment # Reflect experiment. experiment.reflect(*args) Reflekt.increase_count(@caller_object, @method) 🔥"> Reflected experiment ##{index + 1} for #{@method}()", experiment.status, :result, @klass # Save experiment. @db.get("reflections").push(experiment.serialize()) end # Save results. @db.write() end end |