reflekt 1.0.5 → 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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/lib/accessor.rb +45 -0
  3. data/lib/action.rb +127 -0
  4. data/lib/action_stack.rb +44 -0
  5. data/lib/{Clone.rb → clone.rb} +11 -11
  6. data/lib/config.rb +48 -0
  7. data/lib/control.rb +81 -0
  8. data/lib/experiment.rb +99 -0
  9. data/lib/meta.rb +75 -0
  10. data/lib/meta/array_meta.rb +32 -0
  11. data/lib/meta/boolean_meta.rb +26 -0
  12. data/lib/meta/float_meta.rb +26 -0
  13. data/lib/meta/integer_meta.rb +26 -0
  14. data/lib/meta/{NullMeta.rb → null_meta.rb} +21 -19
  15. data/lib/meta/object_meta.rb +35 -0
  16. data/lib/meta/string_meta.rb +26 -0
  17. data/lib/meta_builder.rb +100 -0
  18. data/lib/reflection.rb +123 -0
  19. data/lib/reflekt.rb +277 -0
  20. data/lib/renderer.rb +38 -0
  21. data/lib/rule.rb +54 -0
  22. data/lib/rule_set.rb +110 -0
  23. data/lib/rule_set_aggregator.rb +260 -0
  24. data/lib/rules/array_rule.rb +94 -0
  25. data/lib/rules/boolean_rule.rb +43 -0
  26. data/lib/rules/float_rule.rb +55 -0
  27. data/lib/rules/integer_rule.rb +55 -0
  28. data/lib/rules/null_rule.rb +35 -0
  29. data/lib/rules/object_rule.rb +42 -0
  30. data/lib/rules/string_rule.rb +75 -0
  31. data/lib/web/index.html +3 -4
  32. metadata +46 -29
  33. data/lib/Accessor.rb +0 -37
  34. data/lib/Action.rb +0 -88
  35. data/lib/ActionStack.rb +0 -44
  36. data/lib/Aggregator.rb +0 -260
  37. data/lib/Config.rb +0 -42
  38. data/lib/Control.rb +0 -83
  39. data/lib/Meta.rb +0 -71
  40. data/lib/MetaBuilder.rb +0 -84
  41. data/lib/Reflection.rb +0 -195
  42. data/lib/Reflekt.rb +0 -243
  43. data/lib/Renderer.rb +0 -39
  44. data/lib/Rule.rb +0 -52
  45. data/lib/RuleSet.rb +0 -109
  46. data/lib/meta/ArrayMeta.rb +0 -34
  47. data/lib/meta/BooleanMeta.rb +0 -26
  48. data/lib/meta/FloatMeta.rb +0 -26
  49. data/lib/meta/IntegerMeta.rb +0 -26
  50. data/lib/meta/StringMeta.rb +0 -26
  51. data/lib/rules/ArrayRule.rb +0 -88
  52. data/lib/rules/BooleanRule.rb +0 -47
  53. data/lib/rules/FloatRule.rb +0 -57
  54. data/lib/rules/IntegerRule.rb +0 -57
  55. data/lib/rules/NullRule.rb +0 -33
  56. data/lib/rules/StringRule.rb +0 -81
@@ -0,0 +1,55 @@
1
+ require_relative '../rule'
2
+
3
+ module Reflekt
4
+ class IntegerRule < Rule
5
+
6
+ def initialize()
7
+ @type = :int
8
+ @min = nil
9
+ @max = nil
10
+ end
11
+
12
+ ##
13
+ # @param meta [IntegerMeta]
14
+ ##
15
+ def train(meta)
16
+ value = meta[:value]
17
+
18
+ if @min.nil?
19
+ @min = value
20
+ else
21
+ @min = value if value < @min
22
+ end
23
+
24
+ if @max.nil?
25
+ @max = value
26
+ else
27
+ @max = value if value > @max
28
+ end
29
+ end
30
+
31
+ ##
32
+ # @param value [Integer]
33
+ ##
34
+ def test(value)
35
+ # Numbers only; if the value is a string then there will be no min/max.
36
+ unless @min.nil? || @max.nil?
37
+ return false if value < @min
38
+ return false if value > @max
39
+ end
40
+ end
41
+
42
+ def result()
43
+ {
44
+ :type => @type,
45
+ :min => @min,
46
+ :max => @max
47
+ }
48
+ end
49
+
50
+ def random()
51
+ rand(@min..@max)
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../rule'
2
+
3
+ module Reflekt
4
+ class NullRule < Rule
5
+
6
+ def initialize()
7
+ @type = :null
8
+ end
9
+
10
+ ##
11
+ # @param meta [NullMeta]
12
+ ##
13
+ def train(meta)
14
+ # No need to train as NullMeta is always nil.
15
+ end
16
+
17
+ ##
18
+ # @param value [NilClass]
19
+ ##
20
+ def test(value)
21
+ value.nil?
22
+ end
23
+
24
+ def result()
25
+ {
26
+ :type => @type
27
+ }
28
+ end
29
+
30
+ def random()
31
+ nil
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../rule'
2
+
3
+ module Reflekt
4
+ class ObjectRule < Rule
5
+
6
+ def initialize()
7
+ @type = :object
8
+ @class_type = nil
9
+ # TODO: Populate with meta for each arg.
10
+ @class_args = []
11
+ end
12
+
13
+ ##
14
+ # @param meta [ObjectMeta]
15
+ ##
16
+ def train(meta)
17
+ if @class_type.nil?
18
+ @class_type = meta[:class_type]
19
+ end
20
+ end
21
+
22
+ ##
23
+ # @param value [NilClass]
24
+ ##
25
+ def test(value)
26
+ value.class.to_s == @class_type
27
+ end
28
+
29
+ def result()
30
+ {
31
+ :type => @type,
32
+ :class_type => @class_type
33
+ }
34
+ end
35
+
36
+ def random()
37
+ # TODO: Instantiate class with appropriate @class_args metadata.
38
+ eval("#{@class_type}").new()
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,75 @@
1
+ require_relative '../rule'
2
+
3
+ module Reflekt
4
+ class StringRule < Rule
5
+
6
+ attr_accessor :min_length
7
+ attr_accessor :max_length
8
+
9
+ def initialize()
10
+ @type = :string
11
+ @min_length = nil
12
+ @max_length = nil
13
+ end
14
+
15
+ ##
16
+ # @param meta [StringMeta]
17
+ ##
18
+ def train(meta)
19
+ length = meta[:length]
20
+
21
+ if @min_length.nil?
22
+ @min_length = length
23
+ else
24
+ @min_length = length if length < @min_length
25
+ end
26
+
27
+ if @max_length.nil?
28
+ @max_length = length
29
+ else
30
+ @max_length = length if length > @max_length
31
+ end
32
+ end
33
+
34
+ ##
35
+ # @param value [String]
36
+ ##
37
+ def test(value)
38
+ length = value.length
39
+
40
+ return false if length < @min_length
41
+ return false if length > @max_length
42
+ true
43
+ end
44
+
45
+ def result()
46
+ {
47
+ :type => @type,
48
+ :min_length => @min_length,
49
+ :max_length => @max_length
50
+ }
51
+ end
52
+
53
+ def random()
54
+ # Pour alphabet soup.
55
+ alpha_numeric = Array('A'..'Z') + Array('a'..'z')
56
+ 10.times do
57
+ alpha_numeric << ' '
58
+ end
59
+
60
+ # Dip ladle into alphabet soup.
61
+ last_char = nil
62
+ sentence = Array.new(rand(@min_length..@max_length)) do |index|
63
+ char = alpha_numeric.sample
64
+ # Put no character next to the same character twice.
65
+ while char == last_char
66
+ char = alpha_numeric.sample
67
+ end
68
+ last_char = char
69
+ end
70
+
71
+ return sentence.join
72
+ end
73
+
74
+ end
75
+ end
data/lib/web/index.html CHANGED
@@ -2,12 +2,11 @@
2
2
  <html>
3
3
 
4
4
  <!-- Open this file in a browser to view reflections. -->
5
- <!-- This file is tracked by git so that it shows in editors. -->
5
+ <!-- This file is tracked by Git so that it shows in text editor file browsers. -->
6
6
 
7
7
  <head>
8
8
  <meta charset="UTF-8" />
9
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
10
- <title>Reflekt</title>
9
+ <title>Reflections</title>
11
10
  </head>
12
11
 
13
12
  <body>
@@ -15,7 +14,7 @@
15
14
  <div id="root"></div>
16
15
 
17
16
  <noscript>
18
- You need to enable JavaScript to run this app.
17
+ You need to enable JavaScript to view reflections.
19
18
  </noscript>
20
19
 
21
20
  <script src="db.js"></script>
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.10
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: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rowdb
@@ -24,38 +24,55 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: lit-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Testing that's completely automated.
28
42
  email: maediprichard@gmail.com
29
43
  executables: []
30
44
  extensions: []
31
45
  extra_rdoc_files: []
32
46
  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
47
+ - lib/accessor.rb
48
+ - lib/action.rb
49
+ - lib/action_stack.rb
50
+ - lib/clone.rb
51
+ - lib/config.rb
52
+ - lib/control.rb
53
+ - lib/experiment.rb
54
+ - lib/meta.rb
55
+ - lib/meta/array_meta.rb
56
+ - lib/meta/boolean_meta.rb
57
+ - lib/meta/float_meta.rb
58
+ - lib/meta/integer_meta.rb
59
+ - lib/meta/null_meta.rb
60
+ - lib/meta/object_meta.rb
61
+ - lib/meta/string_meta.rb
62
+ - lib/meta_builder.rb
63
+ - lib/reflection.rb
64
+ - lib/reflekt.rb
65
+ - lib/renderer.rb
66
+ - lib/rule.rb
67
+ - lib/rule_set.rb
68
+ - lib/rule_set_aggregator.rb
69
+ - lib/rules/array_rule.rb
70
+ - lib/rules/boolean_rule.rb
71
+ - lib/rules/float_rule.rb
72
+ - lib/rules/integer_rule.rb
73
+ - lib/rules/null_rule.rb
74
+ - lib/rules/object_rule.rb
75
+ - lib/rules/string_rule.rb
59
76
  - lib/web/README.md
60
77
  - lib/web/bundle.js
61
78
  - lib/web/gitignore.txt
@@ -63,7 +80,7 @@ files:
63
80
  - lib/web/package-lock.json
64
81
  - lib/web/package.json
65
82
  - lib/web/server.js
66
- homepage: https://github.com/refIekt/reflekt
83
+ homepage: https://reflekt.dev
67
84
  licenses:
68
85
  - MPL-2.0
69
86
  metadata: {}
data/lib/Accessor.rb DELETED
@@ -1,37 +0,0 @@
1
- ################################################################################
2
- # Access variables via one object to avoid polluting the caller class scope.
3
- #
4
- # @pattern Singleton
5
- #
6
- # @note Some variables are not accessed via Accessor:
7
- # - @reflekt_counts on the instance
8
- # - @@reflekt_skipped_methods on the instance's singleton class
9
- ################################################################################
10
-
11
- class Accessor
12
-
13
- attr_accessor :config
14
- attr_accessor :setup
15
- attr_accessor :db
16
- attr_accessor :stack
17
- attr_accessor :aggregator
18
- attr_accessor :renderer
19
- attr_accessor :path
20
- attr_accessor :output_path
21
- attr_accessor :error
22
-
23
- def initialize()
24
-
25
- @config = nil
26
- @setup = nil
27
- @db = nil
28
- @stack = nil
29
- @aggregator = nil
30
- @renderer = nil
31
- @path = nil
32
- @output_path = nil
33
- @error = false
34
-
35
- end
36
-
37
- end
data/lib/Action.rb DELETED
@@ -1,88 +0,0 @@
1
- ################################################################################
2
- # A shadow action.
3
- #
4
- # @hierachy
5
- # 1. Action <- YOU ARE HERE
6
- # 2. Reflection
7
- # 3. Meta
8
- ################################################################################
9
-
10
- class Action
11
-
12
- attr_accessor :unique_id
13
- attr_accessor :caller_object
14
- attr_accessor :caller_id
15
- attr_accessor :caller_class
16
- attr_accessor :klass
17
- attr_accessor :method
18
- attr_accessor :base
19
- attr_accessor :parent
20
- attr_accessor :child
21
- attr_accessor :control
22
- attr_accessor :reflections
23
- attr_accessor :is_reflecting
24
- attr_accessor :is_base
25
-
26
- ##
27
- # Create Action.
28
- #
29
- # @param object [Object] The calling object.
30
- # @param method [Symbol] The calling method.
31
- # @param reflect_amount [Integer] The number of reflections to create per action.
32
- # @param stack [ActionStack] The shadow action call stack.
33
- ##
34
- def initialize(caller_object, method, reflect_amount, stack)
35
-
36
- @time = Time.now.to_i
37
- @unique_id = @time + rand(1..99999)
38
- @base = nil
39
- @parent = nil
40
- @child = nil
41
-
42
- # Dependency.
43
- @stack = stack
44
-
45
- # Caller.
46
- @caller_object = caller_object
47
- @caller_id = caller_object.object_id
48
- @caller_class = caller_object.class
49
- @klass = @caller_class.to_s.to_sym
50
- @method = method
51
-
52
- # Reflections.
53
- @control = nil
54
- @reflections = Array.new(reflect_amount)
55
-
56
- # State.
57
- if @stack.peek() == nil
58
- @is_base = true
59
- else
60
- @is_base = false
61
- @base = @stack.base()
62
- end
63
- @is_reflecting = false
64
-
65
- end
66
-
67
- def has_empty_reflections?
68
- @reflections.include? nil
69
- end
70
-
71
- ##
72
- # Is the Action currently reflecting methods?
73
- ##
74
- def is_reflecting?
75
- @is_reflecting
76
- end
77
-
78
- def has_finished_reflecting?
79
- if is_reflecting?
80
- return false
81
- end
82
- if has_empty_reflections?
83
- return false
84
- end
85
- return true
86
- end
87
-
88
- end