reflekt 1.0.8 → 1.0.9

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: 8fca22a79b9c2f962c5bd4583de7c8f35a27e5a350503aac4888d8072a2e843c
4
- data.tar.gz: bf44e0c83c0e1e281b1aab9ecc3b86728152941484995167803d81de28e53170
3
+ metadata.gz: 8ed0b66e3e9110822e6d14ba1a77fc5627b40edea4223d4252fd30ea4853047c
4
+ data.tar.gz: 39990e22a2f9ddac9382a8b960b10ead0b81598db3bf86eac4a1c499182e065b
5
5
  SHA512:
6
- metadata.gz: 3e59ad6e1e3a7e293d904da162c40478ca34a8b6daf0abefd3a0e0e58e525a249cccfd3d36602b0550925efb048e4df4a500c33865e93ebb7a13d2cbb7fea83a
7
- data.tar.gz: b5762a194aa4c94849c4e3540cb9e51e2ea1feb779f51a6f4b424aa4c25aec7410137fb0d5a4ca9c1891ee4b350b58e6a7f34b81d4c57fd0f279a31b509f5b1e
6
+ metadata.gz: 48497c5c451bde6860039fb9570f77a4bd0a9fd4b889d497d9c06079a9e852f3f426e42f01c5480c6bf621f4ba90179e9f95022fcd5e223f3b1da6718936e871
7
+ data.tar.gz: 4e1f58483092d4f7f626878303060c0527ff0838ab244f4abc9e3f5b5772af19c95a5a5e86e1a2d6361027efa80882ead7dafee544698bf895555a7086a63d97
@@ -28,11 +28,12 @@ class Config
28
28
  :int => [IntegerRule],
29
29
  :float => [FloatRule],
30
30
  :null => [NullRule],
31
+ :object => [ObjectRule],
31
32
  :string => [StringRule]
32
33
  }
33
34
 
34
35
  # An absolute path to the directory that contains the output directory.
35
- # Defaults to current action path.
36
+ # Defaults to current execution path.
36
37
  @output_path = nil
37
38
 
38
39
  # Name of output directory.
@@ -79,5 +79,32 @@ class Experiment < Reflection
79
79
 
80
80
  end
81
81
 
82
+ ##
83
+ # Create random values for each argument from control reflections.
84
+ #
85
+ # @param args [Dynamic] The arguments to mirror random values for.
86
+ # @param input_rule_sets [Array] Aggregated rule sets for each argument.
87
+ #
88
+ # @return [Dynamic] Random arguments.
89
+ ##
90
+ def randomize(args, input_rule_sets)
91
+
92
+ random_args = []
93
+
94
+ args.each_with_index do |arg, arg_num|
95
+
96
+ # Get a random rule in the rule set.
97
+ rules = input_rule_sets[arg_num].rules
98
+ agg_rule = rules[rules.keys.sample]
99
+
100
+ # Create a random value that follows that rule.
101
+ random_args << agg_rule.random()
102
+
103
+ end
104
+
105
+ return random_args
106
+
107
+ end
108
+
82
109
  end
83
110
  end
@@ -0,0 +1,35 @@
1
+ ################################################################################
2
+ # A reprsentation of a null value.
3
+ #
4
+ # @hierachy
5
+ # 1. Action
6
+ # 2. Reflection
7
+ # 3. Meta <- YOU ARE HERE
8
+ ################################################################################
9
+
10
+ require_relative '../meta'
11
+
12
+ module Reflekt
13
+ class ObjectMeta < Meta
14
+
15
+ def initialize()
16
+ @type = :object
17
+ @class_type = nil
18
+ end
19
+
20
+ ##
21
+ # @param value [Dynamic] Any custom class.
22
+ ##
23
+ def load(value)
24
+ @class_type = value.class
25
+ end
26
+
27
+ def serialize()
28
+ {
29
+ :type => @type,
30
+ :class_type => @class_type
31
+ }
32
+ end
33
+
34
+ end
35
+ end
@@ -13,7 +13,12 @@ module Reflekt
13
13
  class MetaBuilder
14
14
 
15
15
  ##
16
- # Create meta.
16
+ # Create meta type for matching data type.
17
+ #
18
+ # @flow
19
+ # 1. First return basic type
20
+ # 2. Then return custom type
21
+ # 3. Then return "nil" type
17
22
  #
18
23
  # @param value
19
24
  ##
@@ -22,7 +27,6 @@ class MetaBuilder
22
27
  meta = nil
23
28
  data_type = value.class.to_s
24
29
 
25
- # Create meta type for matching data type.
26
30
  case data_type
27
31
  when "Array"
28
32
  meta = ArrayMeta.new()
@@ -34,6 +38,10 @@ class MetaBuilder
34
38
  meta = IntegerMeta.new()
35
39
  when "String"
36
40
  meta = StringMeta.new()
41
+ else
42
+ unless value.nil?
43
+ meta = ObjectMeta.new()
44
+ end
37
45
  end
38
46
 
39
47
  unless meta.nil?
@@ -78,7 +86,13 @@ class MetaBuilder
78
86
  String => :string
79
87
  }
80
88
 
81
- return meta_types[data_type]
89
+ if meta_types.key? data_type
90
+ return meta_types[data_type]
91
+ elsif value.nil?
92
+ return nil
93
+ else
94
+ return :object
95
+ end
82
96
 
83
97
  end
84
98
 
@@ -70,33 +70,6 @@ class Reflection
70
70
  # Implemented by Control and Experiment.
71
71
  end
72
72
 
73
- ##
74
- # Create random values for each argument from control reflections.
75
- #
76
- # @param args [Dynamic] The arguments to mirror random values for.
77
- # @param input_rule_sets [Array] Aggregated rule sets for each argument.
78
- #
79
- # @return [Dynamic] Random arguments.
80
- ##
81
- def randomize(args, input_rule_sets)
82
-
83
- random_args = []
84
-
85
- args.each_with_index do |arg, arg_num|
86
-
87
- # Get a random rule in the rule set.
88
- rules = input_rule_sets[arg_num].rules
89
- agg_rule = rules[rules.keys.sample]
90
-
91
- # Create a random value that follows that rule.
92
- random_args << agg_rule.random()
93
-
94
- end
95
-
96
- return random_args
97
-
98
- end
99
-
100
73
  ##
101
74
  # Get the results of the reflection.
102
75
  #
@@ -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
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.8
4
+ version: 1.0.9
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-26 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rowdb
@@ -43,6 +43,7 @@ files:
43
43
  - lib/meta/float_meta.rb
44
44
  - lib/meta/integer_meta.rb
45
45
  - lib/meta/null_meta.rb
46
+ - lib/meta/object_meta.rb
46
47
  - lib/meta/string_meta.rb
47
48
  - lib/meta_builder.rb
48
49
  - lib/reflection.rb
@@ -56,6 +57,7 @@ files:
56
57
  - lib/rules/float_rule.rb
57
58
  - lib/rules/integer_rule.rb
58
59
  - lib/rules/null_rule.rb
60
+ - lib/rules/object_rule.rb
59
61
  - lib/rules/string_rule.rb
60
62
  - lib/web/README.md
61
63
  - lib/web/bundle.js