reflekt 1.0.2 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/{Accessor.rb → accessor.rb} +0 -0
  3. data/lib/{Execution.rb → action.rb} +12 -12
  4. data/lib/action_stack.rb +44 -0
  5. data/lib/{Clone.rb → clone.rb} +4 -4
  6. data/lib/{Config.rb → config.rb} +1 -1
  7. data/lib/{Control.rb → control.rb} +14 -12
  8. data/lib/experiment.rb +81 -0
  9. data/lib/{Meta.rb → meta.rb} +5 -5
  10. data/lib/meta/{ArrayMeta.rb → array_meta.rb} +1 -1
  11. data/lib/meta/{BooleanMeta.rb → boolean_meta.rb} +1 -1
  12. data/lib/meta/{FloatMeta.rb → float_meta.rb} +1 -1
  13. data/lib/meta/{IntegerMeta.rb → integer_meta.rb} +1 -1
  14. data/lib/meta/{NullMeta.rb → null_meta.rb} +2 -2
  15. data/lib/meta/{StringMeta.rb → string_meta.rb} +1 -1
  16. data/lib/{MetaBuilder.rb → meta_builder.rb} +2 -2
  17. data/lib/reflection.rb +148 -0
  18. data/lib/{Reflekt.rb → reflekt.rb} +42 -42
  19. data/lib/{Renderer.rb → renderer.rb} +0 -0
  20. data/lib/{Rule.rb → rule.rb} +1 -1
  21. data/lib/{RuleSet.rb → rule_set.rb} +3 -3
  22. data/lib/{Aggregator.rb → rule_set_aggregator.rb} +27 -18
  23. data/lib/rules/{ArrayRule.rb → array_rule.rb} +1 -1
  24. data/lib/rules/{BooleanRule.rb → boolean_rule.rb} +1 -1
  25. data/lib/rules/{FloatRule.rb → float_rule.rb} +1 -1
  26. data/lib/rules/{IntegerRule.rb → integer_rule.rb} +1 -1
  27. data/lib/rules/{NullRule.rb → null_rule.rb} +3 -6
  28. data/lib/rules/{StringRule.rb → string_rule.rb} +1 -1
  29. data/lib/web/bundle.js +2 -2
  30. data/lib/web/package-lock.json +3 -3
  31. data/lib/web/package.json +1 -1
  32. data/lib/web/server.js +5 -5
  33. metadata +30 -29
  34. data/lib/Reflection.rb +0 -193
  35. data/lib/ShadowStack.rb +0 -44
@@ -1,193 +0,0 @@
1
- ################################################################################
2
- # A snapshot of simulated data.
3
- #
4
- # @note
5
- # A reflection's random value is within the bounds of aggregated control rule sets
6
- # as well as as the arg type being inputted into the current control reflection.
7
- #
8
- # @nomenclature
9
- # args, inputs/output and meta represent different stages of a value.
10
- #
11
- # @hierachy
12
- # 1. Execution
13
- # 2. Reflection <- YOU ARE HERE
14
- # 3. Meta
15
- #
16
- # @status
17
- # - :pass [Symbol] The reflection passes the rules.
18
- # - :fail [Symbol] The reflection fails the rules or produces a system error.
19
- # - :error [Symbol] The control reflection produces a system error.
20
- ################################################################################
21
-
22
- require 'Clone'
23
- require 'MetaBuilder'
24
-
25
- class Reflection
26
-
27
- attr_reader :status
28
-
29
- ##
30
- # Create a Reflection.
31
- #
32
- # @param execution [Execution] The Execution that created this Reflection.
33
- # @param number [Integer] Multiple Reflections can be created per Execution.
34
- # @param aggregator [Aggregator] The aggregated RuleSet for this class/method.
35
- ##
36
- def initialize(execution, number, aggregator)
37
-
38
- @execution = execution
39
- @unique_id = execution.unique_id + number
40
- @number = number
41
-
42
- # Dependency.
43
- @aggregator = aggregator
44
-
45
- # Caller.
46
- @klass = execution.klass
47
- @method = execution.method
48
-
49
- # Metadata.
50
- @inputs = nil
51
- @output = nil
52
-
53
- # Clone the execution's calling object.
54
- # TODO: Abstract away into Clone class.
55
- @clone = execution.caller_object.clone
56
-
57
- # Result.
58
- @status = :pass
59
- @time = Time.now.to_i
60
- @message = nil
61
-
62
- end
63
-
64
- ##
65
- # Reflect on a method.
66
- #
67
- # Creates a shadow execution.
68
- # @param *args [Dynamic] The method's arguments.
69
- ##
70
- def reflect(*args)
71
-
72
- # Get aggregated rule sets.
73
- input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
74
- output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
75
-
76
- # When arguments exist.
77
- unless args.size == 0
78
-
79
- # Create random arguments from aggregated rule sets.
80
- unless input_rule_sets.nil?
81
-
82
- # Base random arguments on the types of the current arguments.
83
- if Aggregator.testable?(args, input_rule_sets)
84
-
85
- args = randomize(args, input_rule_sets)
86
-
87
- # TODO: Fallback to argument types from aggregated control rule sets
88
- # when arg types not testable or reflect_amount above 3.
89
- else
90
- @status = :fail
91
- end
92
-
93
- end
94
-
95
- # Create metadata for each argument.
96
- # TODO: Create metadata for other inputs such as properties on the instance.
97
- @inputs = MetaBuilder.create_many(args)
98
-
99
- end
100
-
101
- # Action method with new/old arguments.
102
- begin
103
-
104
- # Run reflection.
105
- output = @clone.send(@method, *args)
106
- @output = MetaBuilder.create(output)
107
-
108
- # Validate output against aggregated control rule sets.
109
- unless output_rule_set.nil?
110
- unless @aggregator.test_output(output, output_rule_set)
111
- @status = :fail
112
- end
113
- end
114
-
115
- # When a system error occurs.
116
- rescue StandardError => message
117
-
118
- @status = :fail
119
- @message = message
120
-
121
- end
122
-
123
- end
124
-
125
- ##
126
- # Create random values for each argument from control reflections.
127
- #
128
- # @param args [Dynamic] The arguments to create random values for.
129
- # @param input_rule_sets [Array] Aggregated rule sets for each argument.
130
- #
131
- # @return [Dynamic] Random arguments.
132
- ##
133
- def randomize(args, input_rule_sets)
134
-
135
- random_args = []
136
-
137
- args.each_with_index do |arg, arg_num|
138
-
139
- rule_type = Aggregator.value_to_rule_type(arg)
140
- agg_rule = input_rule_sets[arg_num].rules[rule_type]
141
-
142
- random_args << agg_rule.random()
143
-
144
- end
145
-
146
- return random_args
147
-
148
- end
149
-
150
- ##
151
- # Get the results of the reflection.
152
- #
153
- # @return [Hash] Reflection metadata.
154
- ##
155
- def serialize()
156
-
157
- # The ID of the first execution in the ShadowStack.
158
- base_id = nil
159
- unless @execution.base == nil
160
- base_id = @execution.base.unique_id
161
- end
162
-
163
- # Build reflection.
164
- reflection = {
165
- :base_id => base_id,
166
- :exe_id => @execution.unique_id,
167
- :ref_id => @unique_id,
168
- :ref_num => @number,
169
- :time => @time,
170
- :class => @klass,
171
- :method => @method,
172
- :status => @status,
173
- :message => @message,
174
- :inputs => nil,
175
- :output => nil,
176
- }
177
-
178
- unless @inputs.nil?
179
- reflection[:inputs] = []
180
- @inputs.each do |meta|
181
- reflection[:inputs] << meta.serialize()
182
- end
183
- end
184
-
185
- unless @output.nil?
186
- reflection[:output] = @output.serialize()
187
- end
188
-
189
- return reflection
190
-
191
- end
192
-
193
- end
@@ -1,44 +0,0 @@
1
- ################################################################################
2
- # Track the executions in a shadow call stack.
3
- #
4
- # @pattern Stack
5
- ################################################################################
6
-
7
- class ShadowStack
8
-
9
- def initialize()
10
- @bottom = nil
11
- @top = nil
12
- end
13
-
14
- def peek()
15
- @top
16
- end
17
-
18
- def base()
19
- @bottom
20
- end
21
-
22
- ##
23
- # Place Execution at the top of stack.
24
- #
25
- # @param execution [Execution] The execution to place.
26
- # @return [Execution] The placed execution.
27
- ##
28
- def push(execution)
29
-
30
- # Place first execution at bottom of stack.
31
- if @bottom.nil?
32
- @bottom = execution
33
- # Connect subsequent executions to each other.
34
- else
35
- @top.parent = execution
36
- execution.child = @top
37
- end
38
-
39
- # Place execution at top of stack.
40
- @top = execution
41
-
42
- end
43
-
44
- end