reflekt 1.0.9 → 1.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ed0b66e3e9110822e6d14ba1a77fc5627b40edea4223d4252fd30ea4853047c
4
- data.tar.gz: 39990e22a2f9ddac9382a8b960b10ead0b81598db3bf86eac4a1c499182e065b
3
+ metadata.gz: 3e5af4cf8808efaeb9b41e29c925aee883139afaea6fef303f060a91566a101b
4
+ data.tar.gz: cb877b7821ed829907c52387b5fc04ff3c986f05646170dceb3307cc14a4d648
5
5
  SHA512:
6
- metadata.gz: 48497c5c451bde6860039fb9570f77a4bd0a9fd4b889d497d9c06079a9e852f3f426e42f01c5480c6bf621f4ba90179e9f95022fcd5e223f3b1da6718936e871
7
- data.tar.gz: 4e1f58483092d4f7f626878303060c0527ff0838ab244f4abc9e3f5b5772af19c95a5a5e86e1a2d6361027efa80882ead7dafee544698bf895555a7086a63d97
6
+ metadata.gz: 6200d9280ccdf2cd5cb1788d80e6795813e5dc7ca398ebca75e507aba2fc8e3bf116ec851f3d103c92eaa1e1a79fd0a6c3f14dc1f59cee74117a8a1f74f60e66
7
+ data.tar.gz: 9b28f16baeafa725c606c0ea458742f86d0b87cda0e95180658b66598a8a08a0efa46f706214d8e00e98eecfc766eadfafeeb47697cf297f62beef95e2ed452d
data/lib/accessor.rb CHANGED
@@ -1,39 +1,45 @@
1
1
  ################################################################################
2
- # Access variables via one object to avoid polluting the caller class scope.
2
+ # Access variables via one object to avoid polluting the caller's scope.
3
3
  #
4
4
  # @pattern Singleton
5
5
  #
6
- # @note Some variables are not accessed via Accessor:
6
+ # @note Variables not accessed via Accessor:
7
7
  # - @reflekt_counts on the instance
8
8
  # - @@reflekt_skipped_methods on the instance's singleton class
9
9
  ################################################################################
10
10
 
11
11
  module Reflekt
12
- class Accessor
13
-
14
- attr_accessor :config
15
- attr_accessor :setup
16
- attr_accessor :db
17
- attr_accessor :stack
18
- attr_accessor :aggregator
19
- attr_accessor :renderer
20
- attr_accessor :path
21
- attr_accessor :output_path
22
- attr_accessor :error
23
-
24
- def initialize()
25
-
26
- @config = nil
27
- @setup = nil
28
- @db = nil
29
- @stack = nil
30
- @aggregator = nil
31
- @renderer = nil
32
- @path = nil
33
- @output_path = nil
34
- @error = false
12
+ class Accessor
35
13
 
36
- end
14
+ attr_accessor :initialized
15
+ attr_accessor :counts
16
+ attr_accessor :error
37
17
 
38
- end
18
+ attr_accessor :config
19
+ attr_accessor :db
20
+ attr_accessor :stack
21
+ attr_accessor :aggregator
22
+ attr_accessor :renderer
23
+
24
+ attr_accessor :package_path
25
+ attr_accessor :project_path
26
+ attr_accessor :output_path
27
+
28
+ def initialize()
29
+ @initialized = false
30
+ @counts = {}
31
+ @error = nil
32
+
33
+ @config = nil
34
+ @db = nil
35
+ @stack = nil
36
+ @aggregator = nil
37
+ @renderer = nil
38
+
39
+ @package_path = nil
40
+ @project_path = nil
41
+ @output_path = nil
42
+ end
43
+
44
+ end
39
45
  end
data/lib/action.rb CHANGED
@@ -8,83 +8,120 @@
8
8
  ################################################################################
9
9
 
10
10
  module Reflekt
11
- class Action
12
-
13
- attr_accessor :unique_id
14
- attr_accessor :caller_object
15
- attr_accessor :caller_id
16
- attr_accessor :caller_class
17
- attr_accessor :klass
18
- attr_accessor :method
19
- attr_accessor :base
20
- attr_accessor :parent
21
- attr_accessor :child
22
- attr_accessor :control
23
- attr_accessor :experiments
24
- attr_accessor :is_reflecting
25
- attr_accessor :is_base
26
-
27
- ##
28
- # Create Action.
29
- #
30
- # @param object [Object] The calling object.
31
- # @param method [Symbol] The calling method.
32
- # @param reflect_amount [Integer] The number of experiments to create per action.
33
- # @param stack [ActionStack] The shadow action call stack.
34
- ##
35
- def initialize(caller_object, method, reflect_amount, stack)
36
-
37
- @time = Time.now.to_i
38
- @unique_id = @time + rand(1..99999)
39
- @base = nil
40
- @parent = nil
41
- @child = nil
42
-
43
- # Dependency.
44
- @stack = stack
45
-
46
- # Caller.
47
- @caller_object = caller_object
48
- @caller_id = caller_object.object_id
49
- @caller_class = caller_object.class
50
- @klass = @caller_class.to_s.to_sym
51
- @method = method
52
-
53
- # Reflections.
54
- @control = nil
55
- @experiments = Array.new(reflect_amount)
56
-
57
- # State.
58
- if @stack.peek() == nil
59
- @is_base = true
60
- else
61
- @is_base = false
62
- @base = @stack.base()
11
+ class Action
12
+ include LitCLI
13
+
14
+ attr_accessor :unique_id
15
+ attr_accessor :caller_object
16
+ attr_accessor :caller_id
17
+ attr_accessor :caller_class
18
+ attr_accessor :klass
19
+ attr_accessor :method
20
+ attr_accessor :base
21
+ attr_accessor :parent
22
+ attr_accessor :child
23
+ attr_accessor :control
24
+ attr_accessor :experiments
25
+ attr_accessor :is_actioned
26
+ attr_accessor :is_reflecting
27
+ attr_accessor :is_base
28
+
29
+ ##
30
+ # Create Action.
31
+ #
32
+ # @param object [Object] The calling object.
33
+ # @param method [Symbol] The calling method.
34
+ # @param reflect_amount [Integer] The number of experiments to create per action.
35
+ # @param stack [ActionStack] The shadow action call stack.
36
+ ##
37
+ def initialize(caller_object, method, config, db, stack, aggregator)
38
+ @time = Time.now.to_i
39
+ @unique_id = @time + rand(1..99999)
40
+ @base = nil
41
+ @child = nil
42
+ @parent = nil
43
+
44
+ # Dependencies.
45
+ @db = db
46
+ @stack = stack
47
+ @aggregator = aggregator
48
+
49
+ # Caller.
50
+ @caller_object = caller_object
51
+ @caller_class = caller_object.class
52
+ @caller_id = caller_object.object_id
53
+ @klass = @caller_class.to_s.to_sym
54
+ @method = method
55
+
56
+ # Reflections.
57
+ @control = nil
58
+ @experiments = Array.new(config.reflect_amount)
59
+
60
+ # State.
61
+ @is_reflecting = false
62
+ if @stack.peek() == nil
63
+ @is_base = true
64
+ else
65
+ @is_base = false
66
+ @base = @stack.base()
67
+ end
63
68
  end
64
- @is_reflecting = false
65
69
 
66
- end
70
+ def reflect(*args)
67
71
 
68
- def has_empty_experiments?
69
- @experiments.include? nil
70
- end
72
+ 🔥"^ Create control for #{@method}()", :info, :control, @klass
73
+ @control = Control.new(self, 0, @aggregator)
71
74
 
72
- ##
73
- # Is the Action currently reflecting methods?
74
- ##
75
- def is_reflecting?
76
- @is_reflecting
77
- end
75
+ @control.reflect(*args)
76
+ 🔥"> Reflected control for #{@method}(): #{args}", @control.status, :result, @klass
77
+
78
+ # Stop reflecting when control fails to execute.
79
+ unless @control.status == :error
80
+
81
+ # Save control.
82
+ @db.get("controls").push(@control.serialize())
83
+ @db.get("reflections").push(@control.serialize())
84
+
85
+ # Multiple experiments per action.
86
+ @experiments.each_with_index do |value, index|
87
+
88
+ 🔥"^ Create experiment ##{index + 1} for #{@method}()", :info, :experiment, @klass
89
+ experiment = Experiment.new(self, index + 1, @aggregator)
90
+ @experiments[index] = experiment
78
91
 
79
- def has_finished_reflecting?
80
- if is_reflecting?
81
- return false
92
+ # Reflect experiment.
93
+ experiment.reflect(*args)
94
+ Reflekt.increase_count(@caller_object, @method)
95
+ 🔥"> Reflected experiment ##{index + 1} for #{@method}()", experiment.status, :result, @klass
96
+
97
+ # Save experiment.
98
+ @db.get("reflections").push(experiment.serialize())
99
+ end
100
+
101
+ # Save results.
102
+ @db.write()
103
+ end
82
104
  end
83
- if has_empty_experiments?
84
- return false
105
+
106
+ def is_actioned?
107
+ @is_actioned
85
108
  end
86
- return true
87
- end
88
109
 
89
- end
110
+ # Is the action currently reflecting methods?
111
+ def is_reflecting?
112
+ @is_reflecting
113
+ end
114
+
115
+ def has_empty_experiments?
116
+ @experiments.include? nil
117
+ end
118
+
119
+ def has_finished_loop?
120
+ return false if is_actioned? == false
121
+ return false if is_reflecting?
122
+ return false if has_empty_experiments?
123
+
124
+ true
125
+ end
126
+ end
90
127
  end
data/lib/action_stack.rb CHANGED
@@ -5,42 +5,40 @@
5
5
  ################################################################################
6
6
 
7
7
  module Reflekt
8
- class ActionStack
8
+ class ActionStack
9
9
 
10
- def initialize()
11
- @bottom = nil
12
- @top = nil
13
- end
14
-
15
- def peek()
16
- @top
17
- end
18
-
19
- def base()
20
- @bottom
21
- end
10
+ def initialize()
11
+ @bottom = nil
12
+ @top = nil
13
+ end
22
14
 
23
- ##
24
- # Place Action at the top of stack.
25
- #
26
- # @param action [Action] The action to place.
27
- # @return [Action] The placed action.
28
- ##
29
- def push(action)
15
+ def peek()
16
+ @top
17
+ end
30
18
 
31
- # Place first action at bottom of stack.
32
- if @bottom.nil?
33
- @bottom = action
34
- # Connect subsequent actions to each other.
35
- else
36
- @top.parent = action
37
- action.child = @top
19
+ def base()
20
+ @bottom
38
21
  end
39
22
 
40
- # Place action at top of stack.
41
- @top = action
23
+ ##
24
+ # Place Action at the top of stack.
25
+ #
26
+ # @param action [Action] The action to place.
27
+ # @return [Action] The placed action.
28
+ ##
29
+ def push(action)
30
+ # First time? Place 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
+ end
42
42
 
43
43
  end
44
-
45
- end
46
44
  end
data/lib/clone.rb CHANGED
@@ -13,21 +13,19 @@
13
13
  ################################################################################
14
14
 
15
15
  module Reflekt
16
- class Clone
16
+ class Clone
17
17
 
18
- def initialize(action)
18
+ def initialize(action)
19
+ # Clone the action's calling object.
20
+ @caller_object_clone = action.caller_object.clone
19
21
 
20
- # Clone the action's calling object.
21
- @caller_object_clone = action.caller_object.clone
22
+ # TODO: Clone any other instances that this clone references.
23
+ # TODO: Replace clone's references to these new instances.
24
+ end
22
25
 
23
- # TODO: Clone any other instances that this clone references.
24
- # TODO: Replace clone's references to these new instances.
26
+ def action(method, *new_args)
27
+ @caller_object_clone.send(method, *new_args)
28
+ end
25
29
 
26
30
  end
27
-
28
- def action(method, *new_args)
29
- @caller_object_clone.send(method, *new_args)
30
- end
31
-
32
- end
33
31
  end
data/lib/config.rb CHANGED
@@ -1,45 +1,48 @@
1
1
  module Reflekt
2
- class Config
3
-
4
- attr_accessor :enabled
5
- attr_accessor :reflect_amount
6
- attr_accessor :reflect_limit
7
- attr_accessor :meta_map
8
- attr_accessor :output_path
9
- attr_accessor :output_directory
10
-
11
- def initialize()
12
-
13
- # Reflekt is enabled by default and should be disabled on production.
14
- @enabled = true
15
-
16
- # The amount of reflections to create per method call.
17
- # A control reflection is created in addition to this.
18
- @reflect_amount = 5
19
-
20
- # The maximum amount of reflections that can be created per instance/method.
21
- # A method called thousands of times doesn't need that many reflections.
22
- @reflect_limit = 10
23
-
24
- # The rules that apply to meta types.
25
- @meta_map = {
26
- :array => [ArrayRule],
27
- :bool => [BooleanRule],
28
- :int => [IntegerRule],
29
- :float => [FloatRule],
30
- :null => [NullRule],
31
- :object => [ObjectRule],
32
- :string => [StringRule]
33
- }
34
-
35
- # An absolute path to the directory that contains the output directory.
36
- # Defaults to current execution path.
37
- @output_path = nil
38
-
39
- # Name of output directory.
40
- @output_directory = "reflections"
2
+ class Config
41
3
 
42
- end
4
+ attr_accessor :enabled
5
+ attr_accessor :reflect_amount
6
+ attr_accessor :reflect_limit
7
+ attr_accessor :meta_map
8
+ attr_accessor :project_path
9
+ attr_accessor :output_directory
43
10
 
44
- end
11
+ def initialize()
12
+
13
+ # Reflekt is enabled by default and should be disabled on production.
14
+ @enabled = true
15
+
16
+ # Reflekt is untracked in git by default.
17
+ @git_ignore = true
18
+
19
+ # The amount of reflections to create per method call.
20
+ # A control reflection is created in addition to this.
21
+ @reflect_amount = 5
22
+
23
+ # The maximum amount of reflections that can be created per instance per method.
24
+ # A method called thousands of times doesn't need that many reflections.
25
+ @reflect_limit = 10
26
+
27
+ # The rules that apply to meta types.
28
+ @meta_map = {
29
+ :array => [ArrayRule],
30
+ :bool => [BooleanRule],
31
+ :int => [IntegerRule],
32
+ :float => [FloatRule],
33
+ :null => [NullRule],
34
+ :object => [ObjectRule],
35
+ :string => [StringRule]
36
+ }
37
+
38
+ # An absolute path to the project root directory.
39
+ # Defaults to current execution path.
40
+ @project_path = Dir.pwd
41
+
42
+ # Name of output directory.
43
+ @output_directory = "reflections"
44
+
45
+ end
46
+
47
+ end
45
48
  end