reflekt 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 457006f1c0a4fbe9a1ce47684aeeec980852cd966f29d07ac57751161f314d52
4
- data.tar.gz: ca01fd9306ece9e1698aab0dcb4945a848a5a910625f8b9394b4f26aa7819514
3
+ metadata.gz: fdefbebdb9516a1fdd8b20c2a5239ae9e2dcc1cb27e5a430589a155a80ccde55
4
+ data.tar.gz: 1c7e77b9ab430f971d9d69332161647762f9065bd73ef4440da0c588520cdd1d
5
5
  SHA512:
6
- metadata.gz: 1de336f083b2e90230453d3ce07cfb36981998587de2e126c88948da75a618ee57a68b32b9869865fb9353b45e85fadc293d98afc2c4669afe8fadc9761fda93
7
- data.tar.gz: 0b00aa43ef7763bc11e93697446ca0e86114818f3e6238d28711d1038eef0c4bc58dc43b1f1f901ec58a4cdf6c9138493e63572a7d33a0363a591e908b38e751
6
+ metadata.gz: 854ac0d582aef56603e8edae7d11371de656cdb044cf6d94a7d6359c440bfd2430ff8eb4456dcc882bf299be681d82735000062decc1274a36e91d6c269afa4a
7
+ data.tar.gz: '05850d0849fbd0e74026e40497761c3355ea67fedc00cb7c2918362d2250b328dd36887a1ffbc2af83bc54787a0a482b258e6eedf66465abbdf6e2df04a604c7'
File without changes
@@ -19,7 +19,7 @@ class Action
19
19
  attr_accessor :parent
20
20
  attr_accessor :child
21
21
  attr_accessor :control
22
- attr_accessor :reflections
22
+ attr_accessor :experiments
23
23
  attr_accessor :is_reflecting
24
24
  attr_accessor :is_base
25
25
 
@@ -28,7 +28,7 @@ class Action
28
28
  #
29
29
  # @param object [Object] The calling object.
30
30
  # @param method [Symbol] The calling method.
31
- # @param reflect_amount [Integer] The number of reflections to create per action.
31
+ # @param reflect_amount [Integer] The number of experiments to create per action.
32
32
  # @param stack [ActionStack] The shadow action call stack.
33
33
  ##
34
34
  def initialize(caller_object, method, reflect_amount, stack)
@@ -51,7 +51,7 @@ class Action
51
51
 
52
52
  # Reflections.
53
53
  @control = nil
54
- @reflections = Array.new(reflect_amount)
54
+ @experiments = Array.new(reflect_amount)
55
55
 
56
56
  # State.
57
57
  if @stack.peek() == nil
@@ -64,8 +64,8 @@ class Action
64
64
 
65
65
  end
66
66
 
67
- def has_empty_reflections?
68
- @reflections.include? nil
67
+ def has_empty_experiments?
68
+ @experiments.include? nil
69
69
  end
70
70
 
71
71
  ##
@@ -79,7 +79,7 @@ class Action
79
79
  if is_reflecting?
80
80
  return false
81
81
  end
82
- if has_empty_reflections?
82
+ if has_empty_experiments?
83
83
  return false
84
84
  end
85
85
  return true
File without changes
File without changes
File without changes
@@ -18,15 +18,15 @@
18
18
  # - :error [Symbol] The control reflection produces a system error.
19
19
  ################################################################################
20
20
 
21
- require 'Reflection'
22
- require 'MetaBuilder'
21
+ require_relative 'reflection'
22
+ require_relative 'meta_builder'
23
23
 
24
24
  class Control < Reflection
25
25
 
26
26
  ##
27
27
  # Reflect on a method.
28
28
  #
29
- # Creates a shadow action.
29
+ # Create a shadow action.
30
30
  # @param *args [Dynamic] The method's arguments.
31
31
  ##
32
32
  def reflect(*args)
@@ -0,0 +1,81 @@
1
+ ################################################################################
2
+ # A snapshot of random data.
3
+ #
4
+ # @note
5
+ # A reflection's random values are generated from aggregated control rule sets.
6
+ #
7
+ # @nomenclature
8
+ # args, inputs/output and meta represent different stages of a value.
9
+ #
10
+ # @hierachy
11
+ # 1. Action
12
+ # 2. Experiment <- YOU ARE HERE
13
+ # 3. Meta
14
+ #
15
+ # @status
16
+ # - :pass [Symbol] The reflection passes the rules.
17
+ # - :fail [Symbol] The reflection fails the rules or produces a system error.
18
+ # - :error [Symbol] The control reflection produces a system error.
19
+ ################################################################################
20
+
21
+ require_relative 'reflection'
22
+ require_relative 'meta_builder'
23
+
24
+ class Experiment < Reflection
25
+
26
+ ##
27
+ # Reflect on a method.
28
+ #
29
+ # Create a shadow action.
30
+ # @param *args [Dynamic] The method's arguments.
31
+ ##
32
+ def reflect(*args)
33
+
34
+ # Get aggregated rule sets.
35
+ input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
36
+ output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
37
+
38
+ # Fail when no trained rule sets.
39
+ if input_rule_sets.nil?
40
+ @status = :fail
41
+ end
42
+
43
+ # When arguments exist.
44
+ unless args.size == 0
45
+
46
+ # Create random arguments from aggregated rule sets.
47
+ unless input_rule_sets.nil?
48
+ args = randomize(args, input_rule_sets)
49
+ end
50
+
51
+ # Create metadata for each argument.
52
+ # TODO: Create metadata for other inputs such as instance variables.
53
+ @inputs = MetaBuilder.create_many(args)
54
+
55
+ end
56
+
57
+ # Action method with random arguments.
58
+ begin
59
+
60
+ # Run reflection.
61
+ output = @clone.send(@method, *args)
62
+ @output = MetaBuilder.create(output)
63
+
64
+ # Validate output against aggregated control rule sets.
65
+ unless output_rule_set.nil?
66
+ unless @aggregator.test_output(output, output_rule_set)
67
+ @status = :fail
68
+ end
69
+ end
70
+
71
+ # When a system error occurs.
72
+ rescue StandardError => message
73
+
74
+ @status = :fail
75
+ @message = message
76
+
77
+ end
78
+
79
+ end
80
+
81
+ end
File without changes
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class ArrayMeta < Meta
4
4
 
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class BooleanMeta < Meta
4
4
 
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class FloatMeta < Meta
4
4
 
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class IntegerMeta < Meta
4
4
 
@@ -10,7 +10,7 @@
10
10
  # 3. Meta <- YOU ARE HERE
11
11
  ################################################################################
12
12
 
13
- require 'Meta'
13
+ require_relative '../meta'
14
14
 
15
15
  class NullMeta < Meta
16
16
 
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class StringMeta < Meta
4
4
 
@@ -5,9 +5,9 @@
5
5
  # @see lib/meta for each meta.
6
6
  ################################################################################
7
7
 
8
- require 'Meta'
8
+ require_relative 'meta'
9
9
  # Require all meta.
10
- Dir[File.join(__dir__, 'meta', '*.rb')].each { |file| require file }
10
+ Dir[File.join(__dir__, 'meta', '*.rb')].each { |file| require_relative file }
11
11
 
12
12
  class MetaBuilder
13
13
 
@@ -1,9 +1,7 @@
1
1
  ################################################################################
2
- # A snapshot of random data.
2
+ # A snapshot of real or random data.
3
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.
4
+ # @pattern Abstract class
7
5
  #
8
6
  # @nomenclature
9
7
  # args, inputs/output and meta represent different stages of a value.
@@ -19,19 +17,19 @@
19
17
  # - :error [Symbol] The control reflection produces a system error.
20
18
  ################################################################################
21
19
 
22
- require 'Clone'
23
- require 'MetaBuilder'
20
+ require_relative 'clone'
21
+ require_relative 'meta_builder'
24
22
 
25
23
  class Reflection
26
24
 
27
25
  attr_reader :status
28
26
 
29
27
  ##
30
- # Create a Reflection.
28
+ # Create a reflection.
31
29
  #
32
30
  # @param action [Action] The Action that created this Reflection.
33
31
  # @param number [Integer] Multiple Reflections can be created per Action.
34
- # @param aggregator [Aggregator] The aggregated RuleSet for this class/method.
32
+ # @param aggregator [RuleSetAggregator] The aggregated RuleSet for this class/method.
35
33
  ##
36
34
  def initialize(action, number, aggregator)
37
35
 
@@ -64,56 +62,11 @@ class Reflection
64
62
  ##
65
63
  # Reflect on a method.
66
64
  #
67
- # Creates a shadow action.
65
+ # Create a shadow action.
68
66
  # @param *args [Dynamic] The method's arguments.
69
67
  ##
70
68
  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
- # Fail when no trained rule sets.
77
- if input_rule_sets.nil?
78
- @status = :fail
79
- end
80
-
81
- # When arguments exist.
82
- unless args.size == 0
83
-
84
- # Create random arguments from aggregated rule sets.
85
- unless input_rule_sets.nil?
86
- args = randomize(args, input_rule_sets)
87
- end
88
-
89
- # Create metadata for each argument.
90
- # TODO: Create metadata for other inputs such as instance variables.
91
- @inputs = MetaBuilder.create_many(args)
92
-
93
- end
94
-
95
- # Action method with random arguments.
96
- begin
97
-
98
- # Run reflection.
99
- output = @clone.send(@method, *args)
100
- @output = MetaBuilder.create(output)
101
-
102
- # Validate output against aggregated control rule sets.
103
- unless output_rule_set.nil?
104
- unless @aggregator.test_output(output, output_rule_set)
105
- @status = :fail
106
- end
107
- end
108
-
109
- # When a system error occurs.
110
- rescue StandardError => message
111
-
112
- @status = :fail
113
- @message = message
114
-
115
- end
116
-
69
+ # Implemented by Control and Experiment.
117
70
  end
118
71
 
119
72
  ##
@@ -19,16 +19,16 @@
19
19
  require 'set'
20
20
  require 'erb'
21
21
  require 'rowdb'
22
- require 'Accessor'
23
- require 'Action'
24
- require 'ActionStack'
25
- require 'Aggregator'
26
- require 'Config'
27
- require 'Control'
28
- require 'Reflection'
29
- require 'Renderer'
22
+ require_relative 'accessor'
23
+ require_relative 'action'
24
+ require_relative 'action_stack'
25
+ require_relative 'config'
26
+ require_relative 'control'
27
+ require_relative 'experiment'
28
+ require_relative 'renderer'
29
+ require_relative 'rule_set_aggregator'
30
30
  # Require all rules.
31
- Dir[File.join(__dir__, 'rules', '*.rb')].each { |file| require file }
31
+ Dir[File.join(__dir__, 'rules', '*.rb')].each { |file| require_relative file }
32
32
 
33
33
  module Reflekt
34
34
 
@@ -75,7 +75,7 @@ module Reflekt
75
75
  # The first method call in the action creates a reflection.
76
76
  # Then method calls are shadow actions which return to the reflection.
77
77
  ##
78
- if action.has_empty_reflections? && !action.is_reflecting?
78
+ if action.has_empty_experiments? && !action.is_reflecting?
79
79
  action.is_reflecting = true
80
80
 
81
81
  # Create control.
@@ -94,19 +94,19 @@ module Reflekt
94
94
  # Save control as a reflection.
95
95
  @@reflekt.db.get("reflections").push(control.serialize())
96
96
 
97
- # Multiple reflections per action.
98
- action.reflections.each_with_index do |value, index|
97
+ # Multiple experiments per action.
98
+ action.experiments.each_with_index do |value, index|
99
99
 
100
- # Create reflection.
101
- reflection = Reflection.new(action, index + 1, @@reflekt.aggregator)
102
- action.reflections[index] = reflection
100
+ # Create experiment.
101
+ experiment = Experiment.new(action, index + 1, @@reflekt.aggregator)
102
+ action.experiments[index] = experiment
103
103
 
104
- # Execute reflection.
105
- reflection.reflect(*args)
104
+ # Execute experiment.
105
+ experiment.reflect(*args)
106
106
  @reflekt_counts[method] = @reflekt_counts[method] + 1
107
107
 
108
- # Save reflection.
109
- @@reflekt.db.get("reflections").push(reflection.serialize())
108
+ # Save experiment.
109
+ @@reflekt.db.get("reflections").push(experiment.serialize())
110
110
 
111
111
  end
112
112
 
@@ -202,7 +202,7 @@ module Reflekt
202
202
  @@reflekt.stack = ActionStack.new()
203
203
 
204
204
  # Create aggregated rule sets.
205
- @@reflekt.aggregator = Aggregator.new(@@reflekt.config.meta_map)
205
+ @@reflekt.aggregator = RuleSetAggregator.new(@@reflekt.config.meta_map)
206
206
  @@reflekt.aggregator.train(db[:controls])
207
207
 
208
208
  # Create renderer.
File without changes
@@ -4,7 +4,7 @@
4
4
  # @pattern Abstract class
5
5
  #
6
6
  # @hierachy
7
- # 1. Aggregator
7
+ # 1. RuleSetAggregator
8
8
  # 2. RuleSet
9
9
  # 3. Rule <- YOU ARE HERE
10
10
  #
@@ -6,14 +6,14 @@
6
6
  # - Builder
7
7
  #
8
8
  # @hierachy
9
- # 1. Aggregator
9
+ # 1. RuleSetAggregator
10
10
  # 2. RuleSet <- YOU ARE HERE
11
11
  # 3. Rule
12
12
  ################################################################################
13
13
 
14
14
  require 'set'
15
- require 'MetaBuilder'
16
- require_relative './meta/NullMeta.rb'
15
+ require_relative 'meta_builder'
16
+ require_relative 'meta/null_meta.rb'
17
17
 
18
18
  class RuleSet
19
19
 
@@ -5,14 +5,14 @@
5
5
  # @pattern Singleton
6
6
  #
7
7
  # @hierachy
8
- # 1. Aggregator <- YOU ARE HERE
8
+ # 1. RuleSetAggregator <- YOU ARE HERE
9
9
  # 2. RuleSet
10
10
  # 3. Rule
11
11
  ################################################################################
12
12
 
13
- require 'RuleSet'
13
+ require_relative 'rule_set'
14
14
 
15
- class Aggregator
15
+ class RuleSetAggregator
16
16
 
17
17
  ##
18
18
  # @param meta_map [Hash] The rules that apply to each meta type.
@@ -1,4 +1,4 @@
1
- require 'Rule'
1
+ require_relative '../rule'
2
2
 
3
3
  class ArrayRule < Rule
4
4
 
@@ -1,5 +1,5 @@
1
1
  require 'set'
2
- require 'Rule'
2
+ require_relative '../rule'
3
3
 
4
4
  class BooleanRule < Rule
5
5
 
@@ -1,4 +1,4 @@
1
- require 'Rule'
1
+ require_relative '../rule'
2
2
 
3
3
  class FloatRule < Rule
4
4
 
@@ -1,4 +1,4 @@
1
- require 'Rule'
1
+ require_relative '../rule'
2
2
 
3
3
  class IntegerRule < Rule
4
4
 
@@ -1,4 +1,4 @@
1
- require 'Rule'
1
+ require_relative '../rule'
2
2
 
3
3
  class NullRule < Rule
4
4
 
@@ -1,4 +1,4 @@
1
- require 'Rule'
1
+ require_relative '../rule'
2
2
 
3
3
  class StringRule < Rule
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflekt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2020-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rowdb
@@ -30,32 +30,33 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - lib/Accessor.rb
34
- - lib/Action.rb
35
- - lib/ActionStack.rb
36
- - lib/Aggregator.rb
37
- - lib/Clone.rb
38
- - lib/Config.rb
39
- - lib/Control.rb
40
- - lib/Meta.rb
41
- - lib/MetaBuilder.rb
42
- - lib/Reflection.rb
43
- - lib/Reflekt.rb
44
- - lib/Renderer.rb
45
- - lib/Rule.rb
46
- - lib/RuleSet.rb
47
- - lib/meta/ArrayMeta.rb
48
- - lib/meta/BooleanMeta.rb
49
- - lib/meta/FloatMeta.rb
50
- - lib/meta/IntegerMeta.rb
51
- - lib/meta/NullMeta.rb
52
- - lib/meta/StringMeta.rb
53
- - lib/rules/ArrayRule.rb
54
- - lib/rules/BooleanRule.rb
55
- - lib/rules/FloatRule.rb
56
- - lib/rules/IntegerRule.rb
57
- - lib/rules/NullRule.rb
58
- - lib/rules/StringRule.rb
33
+ - lib/accessor.rb
34
+ - lib/action.rb
35
+ - lib/action_stack.rb
36
+ - lib/clone.rb
37
+ - lib/config.rb
38
+ - lib/control.rb
39
+ - lib/experiment.rb
40
+ - lib/meta.rb
41
+ - lib/meta/array_meta.rb
42
+ - lib/meta/boolean_meta.rb
43
+ - lib/meta/float_meta.rb
44
+ - lib/meta/integer_meta.rb
45
+ - lib/meta/null_meta.rb
46
+ - lib/meta/string_meta.rb
47
+ - lib/meta_builder.rb
48
+ - lib/reflection.rb
49
+ - lib/reflekt.rb
50
+ - lib/renderer.rb
51
+ - lib/rule.rb
52
+ - lib/rule_set.rb
53
+ - lib/rule_set_aggregator.rb
54
+ - lib/rules/array_rule.rb
55
+ - lib/rules/boolean_rule.rb
56
+ - lib/rules/float_rule.rb
57
+ - lib/rules/integer_rule.rb
58
+ - lib/rules/null_rule.rb
59
+ - lib/rules/string_rule.rb
59
60
  - lib/web/README.md
60
61
  - lib/web/bundle.js
61
62
  - lib/web/gitignore.txt