reflekt 1.0.1 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) 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} +2 -1
  7. data/lib/{Control.rb → control.rb} +23 -12
  8. data/lib/experiment.rb +81 -0
  9. data/lib/meta.rb +71 -0
  10. data/lib/meta/{ArrayMeta.rb → array_meta.rb} +2 -2
  11. data/lib/meta/{BooleanMeta.rb → boolean_meta.rb} +2 -2
  12. data/lib/meta/{FloatMeta.rb → float_meta.rb} +2 -2
  13. data/lib/meta/{IntegerMeta.rb → integer_meta.rb} +2 -2
  14. data/lib/meta/null_meta.rb +34 -0
  15. data/lib/meta/{StringMeta.rb → string_meta.rb} +2 -2
  16. data/lib/{MetaBuilder.rb → meta_builder.rb} +3 -2
  17. data/lib/reflection.rb +148 -0
  18. data/lib/{Reflekt.rb → reflekt.rb} +44 -44
  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} +26 -20
  22. data/lib/{Aggregator.rb → rule_set_aggregator.rb} +44 -22
  23. data/lib/rules/{ArrayRule.rb → array_rule.rb} +1 -1
  24. data/lib/rules/{BooleanRule.rb → boolean_rule.rb} +6 -4
  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/null_rule.rb +33 -0
  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 -27
  34. data/lib/Meta.rb +0 -39
  35. data/lib/Reflection.rb +0 -186
  36. data/lib/ShadowStack.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfaf70b43c12867f93934b6b1f2e0d672486b3331369c9c85c0646e54bfc18d2
4
- data.tar.gz: 437bbcdd66ae77ec202360255386edc10d69bcfb2da5b41816b0aed3c3151285
3
+ metadata.gz: fdefbebdb9516a1fdd8b20c2a5239ae9e2dcc1cb27e5a430589a155a80ccde55
4
+ data.tar.gz: 1c7e77b9ab430f971d9d69332161647762f9065bd73ef4440da0c588520cdd1d
5
5
  SHA512:
6
- metadata.gz: 789f134df80a4cb9455274cd36d968f83903f6c474b6974d451ecfea1910799121f815eeecb9162a3b0ea2417f52983f1bb4557a5dd9b729fbdfa3e7325a6b99
7
- data.tar.gz: 3bfb838fb97dda4989fba353db654b9498ce2ff8112f880d0bb5c926ae58865e05916701ec81cf393486b0b279af308a349245c970242879774c172bf12e2e7c
6
+ metadata.gz: 854ac0d582aef56603e8edae7d11371de656cdb044cf6d94a7d6359c440bfd2430ff8eb4456dcc882bf299be681d82735000062decc1274a36e91d6c269afa4a
7
+ data.tar.gz: '05850d0849fbd0e74026e40497761c3355ea67fedc00cb7c2918362d2250b328dd36887a1ffbc2af83bc54787a0a482b258e6eedf66465abbdf6e2df04a604c7'
File without changes
@@ -1,13 +1,13 @@
1
1
  ################################################################################
2
- # A shadow execution.
2
+ # A shadow action.
3
3
  #
4
4
  # @hierachy
5
- # 1. Execution <- YOU ARE HERE
5
+ # 1. Action <- YOU ARE HERE
6
6
  # 2. Reflection
7
7
  # 3. Meta
8
8
  ################################################################################
9
9
 
10
- class Execution
10
+ class Action
11
11
 
12
12
  attr_accessor :unique_id
13
13
  attr_accessor :caller_object
@@ -19,17 +19,17 @@ class Execution
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
 
26
26
  ##
27
- # Create Execution.
27
+ # Create 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 execution.
32
- # @param stack [ShadowStack] The shadow execution call stack.
31
+ # @param reflect_amount [Integer] The number of experiments to create per action.
32
+ # @param stack [ActionStack] The shadow action call stack.
33
33
  ##
34
34
  def initialize(caller_object, method, reflect_amount, stack)
35
35
 
@@ -51,7 +51,7 @@ class Execution
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,12 +64,12 @@ class Execution
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
  ##
72
- # Is the Execution currently reflecting methods?
72
+ # Is the Action currently reflecting methods?
73
73
  ##
74
74
  def is_reflecting?
75
75
  @is_reflecting
@@ -79,7 +79,7 @@ class Execution
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
@@ -0,0 +1,44 @@
1
+ ################################################################################
2
+ # Track the actions in a shadow call stack.
3
+ #
4
+ # @pattern Stack
5
+ ################################################################################
6
+
7
+ class ActionStack
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 Action at the top of stack.
24
+ #
25
+ # @param action [Action] The action to place.
26
+ # @return [Action] The placed action.
27
+ ##
28
+ def push(action)
29
+
30
+ # Place first action at bottom of stack.
31
+ if @bottom.nil?
32
+ @bottom = action
33
+ # Connect subsequent actions to each other.
34
+ else
35
+ @top.parent = action
36
+ action.child = @top
37
+ end
38
+
39
+ # Place action at top of stack.
40
+ @top = action
41
+
42
+ end
43
+
44
+ end
@@ -7,17 +7,17 @@
7
7
  # on object, not indirectly through clone which results in "undefined method".
8
8
  #
9
9
  # @hierachy
10
- # 1. Execution
10
+ # 1. Action
11
11
  # 2. Reflection
12
12
  # 3. Clone <- YOU ARE HERE
13
13
  ################################################################################
14
14
 
15
15
  class Clone
16
16
 
17
- def initialize(execution)
17
+ def initialize(action)
18
18
 
19
- # Clone the execution's calling object.
20
- @caller_object_clone = execution.caller_object.clone
19
+ # Clone the action's calling object.
20
+ @caller_object_clone = action.caller_object.clone
21
21
 
22
22
  # TODO: Clone any other instances that this clone references.
23
23
  # TODO: Replace clone's references to these new instances.
@@ -26,11 +26,12 @@ class Config
26
26
  :bool => [BooleanRule],
27
27
  :int => [IntegerRule],
28
28
  :float => [FloatRule],
29
+ :null => [NullRule],
29
30
  :string => [StringRule]
30
31
  }
31
32
 
32
33
  # An absolute path to the directory that contains the output directory.
33
- # Defaults to current execution path.
34
+ # Defaults to current action path.
34
35
  @output_path = nil
35
36
 
36
37
  # Name of output directory.
@@ -1,51 +1,62 @@
1
1
  ################################################################################
2
2
  # A shapshot of real data.
3
3
  #
4
- # A control's @number property will always be zero.
4
+ # @note
5
+ # A control's @number will always be 0.
6
+ #
7
+ # @nomenclature
8
+ # args, inputs/output and meta represent different stages of a value.
5
9
  #
6
10
  # @hierachy
7
- # 1. Execution
11
+ # 1. Action
8
12
  # 2. Control <- YOU ARE HERE
9
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.
10
19
  ################################################################################
11
20
 
12
- require 'Reflection'
13
- require 'MetaBuilder'
21
+ require_relative 'reflection'
22
+ require_relative 'meta_builder'
14
23
 
15
24
  class Control < Reflection
16
25
 
17
26
  ##
18
27
  # Reflect on a method.
19
28
  #
20
- # Creates a shadow execution.
29
+ # Create a shadow action.
21
30
  # @param *args [Dynamic] The method's arguments.
22
31
  ##
23
32
  def reflect(*args)
24
33
 
25
- # Get aggregated rule sets.
34
+ # Get trained rule sets.
26
35
  input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
27
36
  output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
28
37
 
38
+ # Fail when no trained rule sets.
39
+ if input_rule_sets.nil?
40
+ @status = :fail
41
+ end
42
+
29
43
  # When arguments exist.
30
44
  unless args.size == 0
31
45
 
32
- # When aggregated rule sets exist.
46
+ # Validate arguments against trained rule sets.
33
47
  unless input_rule_sets.nil?
34
-
35
- # Validate arguments against aggregated rule sets.
36
48
  unless @aggregator.test_inputs(args, input_rule_sets)
37
49
  @status = :fail
38
50
  end
39
-
40
51
  end
41
52
 
42
53
  # Create metadata for each argument.
43
- # TODO: Create metadata for other inputs such as properties on the instance.
54
+ # TODO: Create metadata for other inputs such as instance variables.
44
55
  @inputs = MetaBuilder.create_many(args)
45
56
 
46
57
  end
47
58
 
48
- # Action method with new/old arguments.
59
+ # Action method with real arguments.
49
60
  begin
50
61
 
51
62
  # Run reflection.
@@ -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
@@ -0,0 +1,71 @@
1
+ ################################################################################
2
+ # Metadata for input and output.
3
+ #
4
+ # @pattern Abstract class
5
+ # @see lib/meta for each meta.
6
+ #
7
+ # @hierachy
8
+ # 1. Action
9
+ # 2. Reflection
10
+ # 3. Meta <- YOU ARE HERE
11
+ ################################################################################
12
+
13
+ class Meta
14
+
15
+ ##
16
+ # Each meta defines its type.
17
+ ##
18
+ def initialize()
19
+ @type = :null
20
+ end
21
+
22
+ ##
23
+ # Each meta loads values.
24
+ #
25
+ # @param value [Dynamic]
26
+ ##
27
+ def load(value)
28
+ end
29
+
30
+ ##
31
+ # @return [Hash]
32
+ ##
33
+ def serialize()
34
+ {
35
+ :type => @type
36
+ }
37
+ end
38
+
39
+ ##############################################################################
40
+ # CLASS
41
+ ##############################################################################
42
+
43
+ ##
44
+ # Deserialize metadata.
45
+ #
46
+ # @todo Deserialize should create a Meta object.
47
+ # @todo Require each Meta type to handle its own deserialization.
48
+ #
49
+ # @param meta [Hash] The metadata to deserialize.
50
+ # @param meta [Hash]
51
+ ##
52
+ def self.deserialize(meta)
53
+
54
+ # Convert nil meta into NullMeta.
55
+ # Meta is nil when there are no @inputs or @output on the method.
56
+ if meta.nil?
57
+ return NullMeta.new().serialize()
58
+ end
59
+
60
+ # Symbolize keys.
61
+ # TODO: Remove once "Fix Rowdb.get(path)" bug fixed.
62
+ meta = meta.transform_keys(&:to_sym)
63
+
64
+ # Symbolize type value.
65
+ meta[:type] = meta[:type].to_sym
66
+
67
+ return meta
68
+
69
+ end
70
+
71
+ end
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class ArrayMeta < Meta
4
4
 
@@ -22,7 +22,7 @@ class ArrayMeta < Meta
22
22
 
23
23
  end
24
24
 
25
- def result()
25
+ def serialize()
26
26
  {
27
27
  :type => @type,
28
28
  :max => @max,
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class BooleanMeta < Meta
4
4
 
@@ -16,7 +16,7 @@ class BooleanMeta < Meta
16
16
  @value = value.to_s
17
17
  end
18
18
 
19
- def result()
19
+ def serialize()
20
20
  {
21
21
  :type => @type,
22
22
  :value => @value
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class FloatMeta < Meta
4
4
 
@@ -16,7 +16,7 @@ class FloatMeta < Meta
16
16
  @value = value
17
17
  end
18
18
 
19
- def result()
19
+ def serialize()
20
20
  {
21
21
  :type => @type,
22
22
  :value => @value
@@ -1,4 +1,4 @@
1
- require 'Meta'
1
+ require_relative '../meta'
2
2
 
3
3
  class IntegerMeta < Meta
4
4
 
@@ -16,7 +16,7 @@ class IntegerMeta < Meta
16
16
  @value = value
17
17
  end
18
18
 
19
- def result()
19
+ def serialize()
20
20
  {
21
21
  :type => @type,
22
22
  :value => @value