evt-schema 1.2.0.0 → 2.2.4.0

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: 704a380b053fe55d1cd71897c7570349f293aade9de5cd038106f242bd6a814c
4
- data.tar.gz: f13faebfcc2cf8af080ad6ebad304eb0fe670ae21d1cf11b5d54478179c17bbc
3
+ metadata.gz: 42c0ba35a8f9d61ef11d61b103d4c7c37d747475dfb56d72674cbb497b663cfe
4
+ data.tar.gz: ee145e7df6483dd0afcf0ca6754eceda6078b182d6486a0a055b9191c628dca8
5
5
  SHA512:
6
- metadata.gz: bd08ee9817ea5f2bd56c4f809fb8f6528efa284bf4bc6db199141f29117fb872e96e586a29e0bcaec92532151471d1dfb9304badfbf81927286263dd53d478e4
7
- data.tar.gz: f416ce9890f90cf3ca14ee6ecd556cf84190f0113df8b636dcd475ea5b3ffb9e50ea8aa74b0bd30ccd47708f5a5904dd5e955190c546ee7aef369089b0d3543f
6
+ metadata.gz: 11aec5d0798a7fcbf2be9673600fb3b704b8630ffa0caaff7e50915142f15de180f5a0a621fab59deab2e4265d656db669a4db329e42c0b5519eff6e767161c9
7
+ data.tar.gz: 4c2a27e05c3a2978fd788f75a1d1e7c2181286ad430e6c58176b73917160a606b5350d30faf31092adcccb2882e50c9799efe54fc61e9603ff5d095ec215bf5d
@@ -1,10 +1,13 @@
1
1
  require 'attribute'
2
2
  require 'set_attributes'
3
+ require 'initializer'
3
4
  require 'validate'
4
5
  require 'virtual'
5
6
 
6
7
  require 'schema/schema'
7
- require 'schema/schema/assertions'
8
+ require 'schema/schema/compare/comparison'
9
+ require 'schema/schema/compare/comparison/entry'
10
+ require 'schema/schema/compare'
8
11
  require 'schema/schema/attribute'
9
12
  require 'schema/data_structure'
10
13
  require 'schema/validation/nil_attributes'
@@ -1,2 +1,9 @@
1
+ require 'securerandom'
2
+
3
+ require 'schema/controls/random'
4
+ require 'schema/controls/attribute'
1
5
  require 'schema/controls/schema'
6
+ require 'schema/controls/schema/different'
2
7
  require 'schema/controls/data_structure'
8
+ require 'schema/controls/comparison'
9
+ require 'schema/controls/comparison/entry'
@@ -0,0 +1,49 @@
1
+ module Schema
2
+ module Controls
3
+ module Attribute
4
+ module Name
5
+ def self.example
6
+ some_attribute
7
+ end
8
+
9
+ def self.some_attribute
10
+ :some_attribute
11
+ end
12
+
13
+ def self.some_other_attribute
14
+ :some_other_attribute
15
+ end
16
+
17
+ def self.yet_another_attribute
18
+ :yet_another_attribute
19
+ end
20
+
21
+ def self.random
22
+ :"random_attribute_#{Controls::Random.example}"
23
+ end
24
+ end
25
+
26
+ module Value
27
+ def self.some_attribute
28
+ 'some value'
29
+ end
30
+
31
+ def self.some_other_attribute
32
+ 'some other value'
33
+ end
34
+
35
+ def self.yet_another_attribute
36
+ 'yet another value'
37
+ end
38
+
39
+ def self.alternate
40
+ 'some alternate value'
41
+ end
42
+
43
+ def self.random
44
+ Controls::Random.example
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,179 @@
1
+ module Schema
2
+ module Controls
3
+ module Comparison
4
+ def self.example
5
+ Same.example
6
+ end
7
+
8
+ def self.control_class
9
+ Same.control_class
10
+ end
11
+
12
+ def self.compare_class
13
+ Same.compare_class
14
+ end
15
+
16
+ def self.entries
17
+ Same.entries
18
+ end
19
+
20
+ module Same
21
+ def self.example
22
+ ::Schema::Compare::Comparison.new(control_class, compare_class, entries)
23
+ end
24
+
25
+ def self.control_class
26
+ Controls::Schema::Example
27
+ end
28
+
29
+ def self.compare_class
30
+ Controls::Schema::Example
31
+ end
32
+
33
+ def self.entries
34
+ [
35
+ Entry::SomeAttribute.example,
36
+ Entry::SomeOtherAttribute.example
37
+ ]
38
+ end
39
+
40
+ module Mapped
41
+ def self.example
42
+ ::Schema::Compare::Comparison.new(control_class, compare_class, entries)
43
+ end
44
+
45
+ def self.control_class
46
+ Controls::Schema::Example
47
+ end
48
+
49
+ def self.compare_class
50
+ Controls::Schema::Equivalent
51
+ end
52
+
53
+ def self.entries
54
+ [
55
+ Entry::SomeAttribute.example,
56
+ Entry::SomeOtherAttribute::Mapped.example
57
+ ]
58
+ end
59
+ end
60
+ end
61
+
62
+ module Different
63
+ def self.example
64
+ ::Schema::Compare::Comparison.new(control_class, compare_class, entries)
65
+ end
66
+
67
+ def self.control_class
68
+ Classes.control_class
69
+ end
70
+
71
+ def self.compare_class
72
+ Classes.compare_class
73
+ end
74
+
75
+ def self.entries
76
+ Attributes.entries
77
+ end
78
+
79
+ module Attributes
80
+ def self.example
81
+ ::Schema::Compare::Comparison.new(control_class, compare_class, entries)
82
+ end
83
+
84
+ def self.control_class
85
+ Controls::Schema::Example
86
+ end
87
+
88
+ def self.compare_class
89
+ Controls::Schema::Example
90
+ end
91
+
92
+ def self.entries
93
+ [
94
+ Entry::SomeAttribute.example,
95
+ Entry::SomeOtherAttribute::Different.example
96
+ ]
97
+ end
98
+ end
99
+
100
+ module Classes
101
+ def self.example
102
+ ::Schema::Compare::Comparison.new(control_class, compare_class, entries)
103
+ end
104
+
105
+ def self.control_class
106
+ Controls::Schema::Example
107
+ end
108
+
109
+ def self.compare_class
110
+ Controls::Schema::OtherExample
111
+ end
112
+
113
+ def self.entries
114
+ Same.entries
115
+ end
116
+ end
117
+
118
+ module Mapped
119
+ def self.example
120
+ ::Schema::Compare::Comparison.new(control_class, compare_class, entries)
121
+ end
122
+
123
+ def self.control_class
124
+ Controls::Schema::Example
125
+ end
126
+
127
+ def self.compare_class
128
+ Controls::Schema::Equivalent
129
+ end
130
+
131
+ def self.entries
132
+ [
133
+ Entry::SomeAttribute.example,
134
+ Entry::SomeOtherAttribute::Mapped::DifferentValues.example
135
+ ]
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ __END__
144
+
145
+ Controls::Comparison.example
146
+ - Alias for Same
147
+
148
+ Controls::Same.example
149
+ - Same classes
150
+ - Same attribute values
151
+ - Same attribute names
152
+
153
+ Controls::Same::Mapped.example
154
+ - Different classes
155
+ - Same attribute values
156
+ - One attribute's name is different
157
+
158
+ Controls::Different.example
159
+ - Different classes
160
+ - One attribute's values are different
161
+ - The other attribute's values are the same
162
+ - Same attribute names
163
+
164
+ Controls::Different::Attributes.example
165
+ - Same classes
166
+ - One attribute's values are different
167
+ - The other attribute's values are the same
168
+ - Same attribute names
169
+
170
+ Controls::Different::Classes.example
171
+ - Different classes
172
+ - Same attribute values
173
+ - Same attribute names
174
+
175
+ Controls::Different::Mapped.example
176
+ - Different classes
177
+ - One attribute's values are different
178
+ - The other attribute's values are the same
179
+ - One attribute's name is different
@@ -0,0 +1,230 @@
1
+ module Schema
2
+ module Controls
3
+ module Comparison
4
+ module Entry
5
+ def self.example
6
+ SomeAttribute.example
7
+ end
8
+
9
+ module SomeAttribute
10
+ def self.example
11
+ ::Schema::Compare::Comparison::Entry.new(
12
+ self.control_name,
13
+ self.control_value,
14
+ self.compare_name,
15
+ self.compare_value
16
+ )
17
+ end
18
+
19
+ def self.control_name
20
+ Attribute::Name.some_attribute
21
+ end
22
+
23
+ def self.control_value
24
+ Attribute::Value.some_attribute
25
+ end
26
+
27
+ def self.compare_name
28
+ Attribute::Name.some_attribute
29
+ end
30
+
31
+ def self.compare_value
32
+ Attribute::Value.some_attribute
33
+ end
34
+ end
35
+
36
+ module SomeOtherAttribute
37
+ def self.example
38
+ Same.example
39
+ end
40
+
41
+ def self.control_name
42
+ Same.some_other_attribute
43
+ end
44
+
45
+ def self.control_value
46
+ Same.some_other_attribute
47
+ end
48
+
49
+ def self.compare_name
50
+ Same.some_other_attribute
51
+ end
52
+
53
+ def self.compare_value
54
+ Same.some_other_attribute
55
+ end
56
+
57
+ module Same
58
+ def self.example
59
+ ::Schema::Compare::Comparison::Entry.new(
60
+ self.control_name,
61
+ self.control_value,
62
+ self.compare_name,
63
+ self.compare_value
64
+ )
65
+ end
66
+
67
+ def self.control_name
68
+ Attribute::Name.some_other_attribute
69
+ end
70
+
71
+ def self.control_value
72
+ Attribute::Value.some_other_attribute
73
+ end
74
+
75
+ def self.compare_name
76
+ Attribute::Name.some_other_attribute
77
+ end
78
+
79
+ def self.compare_value
80
+ Attribute::Value.some_other_attribute
81
+ end
82
+ end
83
+
84
+ module Different
85
+ def self.example
86
+ ::Schema::Compare::Comparison::Entry.new(
87
+ self.control_name,
88
+ self.control_value,
89
+ self.compare_name,
90
+ self.compare_value
91
+ )
92
+ end
93
+
94
+ def self.control_name
95
+ Attribute::Name.some_other_attribute
96
+ end
97
+
98
+ def self.control_value
99
+ Attribute::Value.some_other_attribute
100
+ end
101
+
102
+ def self.compare_name
103
+ Attribute::Name.some_other_attribute
104
+ end
105
+
106
+ def self.compare_value
107
+ Attribute::Value.alternate
108
+ end
109
+ end
110
+
111
+ module Mapped
112
+ def self.example
113
+ SameValues.example
114
+ end
115
+
116
+ def self.control_name
117
+ SameValues.some_other_attribute
118
+ end
119
+
120
+ def self.control_value
121
+ SameValues.some_other_attribute
122
+ end
123
+
124
+ def self.compare_name
125
+ SameValues.some_other_attribute
126
+ end
127
+
128
+ def self.compare_value
129
+ SameValues.some_other_attribute
130
+ end
131
+
132
+ module SameValues
133
+ def self.example
134
+ ::Schema::Compare::Comparison::Entry.new(
135
+ self.control_name,
136
+ self.control_value,
137
+ self.compare_name,
138
+ self.compare_value
139
+ )
140
+ end
141
+
142
+ def self.control_name
143
+ Attribute::Name.some_other_attribute
144
+ end
145
+
146
+ def self.control_value
147
+ Attribute::Value.some_other_attribute
148
+ end
149
+
150
+ def self.compare_name
151
+ Attribute::Name.yet_another_attribute
152
+ end
153
+
154
+ def self.compare_value
155
+ Attribute::Value.some_other_attribute
156
+ end
157
+ end
158
+
159
+ module DifferentValues
160
+ def self.example
161
+ ::Schema::Compare::Comparison::Entry.new(
162
+ self.control_name,
163
+ self.control_value,
164
+ self.compare_name,
165
+ self.compare_value
166
+ )
167
+ end
168
+
169
+ def self.control_name
170
+ Attribute::Name.some_other_attribute
171
+ end
172
+
173
+ def self.control_value
174
+ Attribute::Value.some_other_attribute
175
+ end
176
+
177
+ def self.compare_name
178
+ Attribute::Name.yet_another_attribute
179
+ end
180
+
181
+ def self.compare_value
182
+ Attribute::Value.alternate
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ Same = SomeAttribute
189
+
190
+ Different = SomeOtherAttribute::Different
191
+
192
+ Mapped = SomeOtherAttribute::Mapped
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ __END__
199
+
200
+ A namespace with "Different" means different values
201
+ A namespace with "Mapped" means different names
202
+ A namespace with neither "Different" nor "Mapped" means the sameness is insignificant
203
+
204
+ puts "SomeAttribute.example"
205
+ pp Schema::Controls::Comparison::Entry::SomeAttribute.example
206
+ puts
207
+
208
+ puts "SomeOtherAttribute.example"
209
+ pp Schema::Controls::Comparison::Entry::SomeOtherAttribute.example
210
+ puts
211
+
212
+ puts "SomeOtherAttribute::Same.example"
213
+ pp Schema::Controls::Comparison::Entry::SomeOtherAttribute::Same.example
214
+ puts
215
+
216
+ puts "SomeOtherAttribute::Different.example"
217
+ pp Schema::Controls::Comparison::Entry::SomeOtherAttribute::Different.example
218
+ puts
219
+
220
+ puts "SomeOtherAttribute::Mapped.example"
221
+ pp Schema::Controls::Comparison::Entry::SomeOtherAttribute::Mapped.example
222
+ puts
223
+
224
+ puts "SomeOtherAttribute::Mapped::SameValues.example"
225
+ pp Schema::Controls::Comparison::Entry::SomeOtherAttribute::Mapped::SameValues.example
226
+ puts
227
+
228
+ puts "SomeOtherAttribute::Mapped::DifferentValues.example"
229
+ pp Schema::Controls::Comparison::Entry::SomeOtherAttribute::Mapped::DifferentValues.example
230
+ puts
@@ -3,10 +3,14 @@ module Schema
3
3
  module DataStructure
4
4
  def self.example
5
5
  example = Example.new
6
- example.some_attribute = 'some value'
6
+ example.some_attribute = some_attribute
7
7
  example
8
8
  end
9
9
 
10
+ def self.some_attribute
11
+ Attribute::Value.some_attribute
12
+ end
13
+
10
14
  def self.ancestors
11
15
  example.class.ancestors
12
16
  end
@@ -17,7 +21,7 @@ module Schema
17
21
 
18
22
  def self.hash
19
23
  {
20
- some_attribute: 'some value'
24
+ some_attribute: some_attribute
21
25
  }
22
26
  end
23
27
 
@@ -29,10 +33,14 @@ module Schema
29
33
  module ExtraAttributes
30
34
  def self.data
31
35
  {
32
- :some_attribute => 'some value',
33
- :some_other_attribute => 'some other value'
36
+ :some_attribute => DataStructure.some_attribute,
37
+ :some_other_attribute => some_other_attribute
34
38
  }
35
39
  end
40
+
41
+ def self.some_other_attribute
42
+ Attribute::Value.some_other_attribute
43
+ end
36
44
  end
37
45
 
38
46
  module ConfigureDependencies
@@ -54,7 +62,7 @@ module Schema
54
62
  module ReadAndWrite
55
63
  def self.example
56
64
  example = Example.new
57
- example.some_attribute = 'some value'
65
+ example.some_attribute = DataStructure.some_attribute
58
66
  example
59
67
  end
60
68
 
@@ -71,7 +79,7 @@ module Schema
71
79
  module Data
72
80
  def self.example
73
81
  {
74
- some_attribute: 'some value'
82
+ some_attribute: DataStructure.some_attribute
75
83
  }
76
84
  end
77
85
  end
@@ -0,0 +1,9 @@
1
+ module Schema
2
+ module Controls
3
+ module Random
4
+ def self.example
5
+ SecureRandom.hex
6
+ end
7
+ end
8
+ end
9
+ end
@@ -3,18 +3,26 @@ module Schema
3
3
  module Schema
4
4
  def self.example
5
5
  example = Example.new
6
- example.some_attribute = 'some value'
7
- example.some_other_attribute = 'some other value'
6
+ example.some_attribute = some_attribute
7
+ example.some_other_attribute = some_other_attribute
8
8
  example
9
9
  end
10
10
 
11
11
  def self.other_example
12
12
  example = OtherExample.new
13
- example.some_attribute = 'some value'
14
- example.some_other_attribute = 'some other value'
13
+ example.some_attribute = some_attribute
14
+ example.some_other_attribute = some_other_attribute
15
15
  example
16
16
  end
17
17
 
18
+ def self.some_attribute
19
+ Attribute::Value.some_attribute
20
+ end
21
+
22
+ def self.some_other_attribute
23
+ Attribute::Value.some_other_attribute
24
+ end
25
+
18
26
  def self.ancestors
19
27
  example.class.ancestors
20
28
  end
@@ -23,25 +31,52 @@ module Schema
23
31
  example.attributes
24
32
  end
25
33
 
34
+ def self.attribute_names
35
+ example.class.attribute_names
36
+ end
37
+
26
38
  def self.hash
27
39
  example.to_h
28
40
  end
29
41
 
42
+ module Attributes
43
+ def self.included(cls)
44
+ cls.class_exec do
45
+ include ::Schema
46
+ attribute :some_attribute
47
+ attribute :some_other_attribute
48
+ end
49
+ end
50
+ end
51
+
30
52
  class Example
31
- include ::Schema
32
- attribute :some_attribute
33
- attribute :some_other_attribute
53
+ include Attributes
34
54
  end
35
55
 
36
- class OtherExample < Example
56
+ class OtherExample
57
+ include Attributes
58
+ end
59
+
60
+ module Random
61
+ def self.example
62
+ example_class.new
63
+ end
64
+
65
+ def self.example_class
66
+ Class.new do
67
+ include ::Schema
68
+
69
+ attribute Attribute::Name.random
70
+ end
71
+ end
37
72
  end
38
73
 
39
74
  module TransientAttributes
40
75
  def self.example
41
76
  example = Example.new
42
- example.some_attribute = 'some value'
43
- example.some_other_attribute = 'some other value'
44
- example.yet_another_attribute = 'yet another value'
77
+ example.some_attribute = Attribute::Value.some_attribute
78
+ example.some_other_attribute = Attribute::Value.some_other_attribute
79
+ example.yet_another_attribute = Attribute::Value.yet_another_attribute
45
80
  example
46
81
  end
47
82
 
@@ -62,11 +97,15 @@ module Schema
62
97
  module Equivalent
63
98
  def self.example
64
99
  example = Example.new
65
- example.some_attribute = 'some value'
66
- example.yet_another_attribute = 'some other value'
100
+ example.some_attribute = Attribute::Value.some_attribute
101
+ example.yet_another_attribute = yet_another_attribute
67
102
  example
68
103
  end
69
104
 
105
+ def self.yet_another_attribute
106
+ Attribute::Value.some_other_attribute
107
+ end
108
+
70
109
  class Example
71
110
  include ::Schema
72
111
  attribute :some_attribute
@@ -0,0 +1,18 @@
1
+ module Schema
2
+ module Controls
3
+ module Schema
4
+ module Different
5
+ def self.attribute_values
6
+ example = Example.new
7
+ example.some_attribute = Controls::Schema.some_attribute
8
+ example.some_other_attribute = some_other_attribute
9
+ example
10
+ end
11
+
12
+ def self.some_other_attribute
13
+ 'some different value'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -29,7 +29,7 @@ module Schema
29
29
  def set_attributes(instance, data, strict)
30
30
  begin
31
31
  SetAttributes.(instance, data, strict: strict)
32
- rescue SetAttributes::Attribute::Error => e
32
+ rescue SetAttributes::Assign::Error => e
33
33
  raise Schema::Error, e.message
34
34
  end
35
35
  end
@@ -3,28 +3,31 @@ module Schema
3
3
 
4
4
  def self.included(cls)
5
5
  cls.class_exec do
6
+ extend Info
6
7
  extend AttributeMacro
7
8
  extend Attributes
8
9
 
9
- # This is done as a countermeasure for incompatibility
10
- # between Virtual and an Assertions module
11
- # include Virtual
12
- # virtual :transform_write
13
- define_method(:transform_write) {|data|}
14
- #
10
+ include Virtual
11
+ virtual :transform_write
15
12
 
16
13
  const_set(:Boolean, Boolean)
17
14
  end
18
15
  end
19
16
 
17
+ module Info
18
+ def type
19
+ name.split('::').last
20
+ end
21
+ end
22
+
20
23
  module AttributeMacro
21
- def attribute_macro(attr_name, type=nil, strict: nil, default: nil)
24
+ def attribute_macro(attribute_name, type=nil, strict: nil, default: nil)
22
25
  if type.nil? && !strict.nil?
23
- raise Schema::Attribute::Error, "The \"#{attr_name}\" attribute is declared with the \"strict\" option but a type is not specified"
26
+ raise Schema::Attribute::Error, "The \"#{attribute_name}\" attribute is declared with the \"strict\" option but a type is not specified"
24
27
  end
25
28
 
26
29
  if type == Boolean && strict == false
27
- raise Schema::Attribute::Error, "The \"#{attr_name}\" attribute is declared with the \"strict\" option disabled but boolean type is specified"
30
+ raise Schema::Attribute::Error, "The \"#{attribute_name}\" attribute is declared with the \"strict\" option disabled but boolean type is specified"
28
31
  end
29
32
 
30
33
  check = nil
@@ -58,9 +61,9 @@ module Schema
58
61
  initialize_value = proc { default }
59
62
  end
60
63
 
61
- ::Attribute::Define.(self, attr_name, :accessor, check: check, &initialize_value)
64
+ ::Attribute::Define.(self, attribute_name, :accessor, check: check, &initialize_value)
62
65
 
63
- attribute = attributes.register(attr_name, type, strict)
66
+ attribute = attributes.register(attribute_name, type, strict)
64
67
  attribute
65
68
  end
66
69
  alias :attribute :attribute_macro
@@ -161,31 +164,12 @@ module Schema
161
164
  end
162
165
  alias :to_h :attributes
163
166
 
164
- def ==(other, attributes=nil, ignore_class: nil)
165
- attributes ||= self.class.attribute_names
166
- attributes = Array(attributes)
167
+ def ==(other, attributes_names=nil, ignore_class: nil)
168
+ comparison = Compare.(self, other, attributes_names)
167
169
 
168
- ignore_class = false if ignore_class.nil?
170
+ different = comparison.different?(ignore_class: ignore_class)
169
171
 
170
- if !ignore_class
171
- return false if self.class != other.class
172
- end
173
-
174
- attributes.each do |attribute|
175
- if attribute.is_a? Hash
176
- this_attribute, other_attribute = attribute.keys.first, attribute.values.first
177
- else
178
- this_attribute, other_attribute = attribute, attribute
179
- end
180
-
181
- return false if public_send(this_attribute) != other.public_send(other_attribute)
182
- end
183
-
184
- true
172
+ !different
185
173
  end
186
174
  alias :eql? :==
187
-
188
- def ===(other)
189
- self.eql?(other, ignore_class: true)
190
- end
191
175
  end
@@ -0,0 +1,7 @@
1
+ module Schema
2
+ module Compare
3
+ def self.call(control, compare, attribute_names=nil)
4
+ Comparison.build(control, compare, attribute_names)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,115 @@
1
+ module Schema
2
+ module Compare
3
+ class Comparison
4
+ include Initializer
5
+
6
+ Error = Class.new(RuntimeError)
7
+
8
+ def entries_attribute_names
9
+ entries.map { |entry| entry.control_name }
10
+ end
11
+ alias :attribute_names :entries_attribute_names
12
+
13
+ initializer :control_class, :compare_class, :entries
14
+
15
+ def self.build(control, compare, attribute_names=nil)
16
+ assure_schemas(control, compare)
17
+
18
+ attribute_names ||= control.class.attribute_names
19
+
20
+ if not attribute_names.is_a?(Array)
21
+ attribute_names = [attribute_names]
22
+ end
23
+
24
+ entries = build_entries(control, compare, attribute_names)
25
+
26
+ new(control.class, compare.class, entries)
27
+ end
28
+
29
+ def self.assure_schemas(control, compare)
30
+ if not control.is_a?(Schema)
31
+ raise Error, 'Control object is not an implementation of Schema'
32
+ end
33
+
34
+ if not compare.is_a?(Schema)
35
+ raise Error, 'Compare object is not an implementation of Schema'
36
+ end
37
+ end
38
+
39
+ def self.build_entries(control, compare, attribute_names)
40
+ attribute_names.map do |attribute_name|
41
+ if attribute_name.is_a?(Hash)
42
+ control_name, compare_name = attribute_name.keys.first, attribute_name.values.first
43
+ else
44
+ control_name, compare_name = attribute_name, attribute_name
45
+ end
46
+
47
+ build_entry(control_name, control, compare_name, compare)
48
+ end
49
+ end
50
+
51
+ def self.build_entry(control_name, control, compare_name, compare)
52
+ control_class = control.class
53
+ if not control_class.attribute_names.include?(control_name)
54
+ raise Error, "Attribute is not defined (Attribute Name: #{control_name.inspect}, Schema Class: #{control_class})"
55
+ end
56
+
57
+ compare_class = compare.class
58
+ if not compare_class.attribute_names.include?(compare_name)
59
+ raise Error, "Attribute is not defined (Attribute Name: #{compare_name.inspect}, Schema Class: #{compare_class})"
60
+ end
61
+
62
+ control_value = control.public_send(control_name)
63
+ compare_value = compare.public_send(compare_name)
64
+
65
+ entry = Entry.new(
66
+ control_name,
67
+ control_value,
68
+ compare_name,
69
+ compare_value
70
+ )
71
+
72
+ entry
73
+ end
74
+
75
+ def entry(attribute_name)
76
+ entries.find do |entry|
77
+ entry.control_name == attribute_name
78
+ end
79
+ end
80
+ alias :[] :entry
81
+
82
+ def different?(attribute_name=nil, ignore_class: nil)
83
+ if not attribute_name.nil?
84
+ return attribute_different?(attribute_name)
85
+ end
86
+
87
+ ignore_class ||= false
88
+
89
+ if not ignore_class
90
+ return true if classes_different?
91
+ end
92
+
93
+ attribute_names.each do |attribute_name|
94
+ return true if attribute_different?(attribute_name)
95
+ end
96
+
97
+ false
98
+ end
99
+
100
+ def classes_different?
101
+ control_class != compare_class
102
+ end
103
+
104
+ def attribute_different?(attribute_name)
105
+ entry = self[attribute_name]
106
+
107
+ if entry.nil?
108
+ raise Error, "No attribute difference entry (Attribute Name: #{attribute_name.inspect})"
109
+ end
110
+
111
+ entry.different?
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,16 @@
1
+ module Schema
2
+ module Compare
3
+ class Comparison
4
+ Entry = Struct.new(
5
+ :control_name,
6
+ :control_value,
7
+ :compare_name,
8
+ :compare_value
9
+ ) do
10
+ def different?
11
+ control_value != compare_value
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.0
4
+ version: 2.2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2020-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-attribute
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: evt-initializer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: evt-validate
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -88,12 +102,19 @@ extra_rdoc_files: []
88
102
  files:
89
103
  - lib/schema.rb
90
104
  - lib/schema/controls.rb
105
+ - lib/schema/controls/attribute.rb
106
+ - lib/schema/controls/comparison.rb
107
+ - lib/schema/controls/comparison/entry.rb
91
108
  - lib/schema/controls/data_structure.rb
109
+ - lib/schema/controls/random.rb
92
110
  - lib/schema/controls/schema.rb
111
+ - lib/schema/controls/schema/different.rb
93
112
  - lib/schema/data_structure.rb
94
113
  - lib/schema/schema.rb
95
- - lib/schema/schema/assertions.rb
96
114
  - lib/schema/schema/attribute.rb
115
+ - lib/schema/schema/compare.rb
116
+ - lib/schema/schema/compare/comparison.rb
117
+ - lib/schema/schema/compare/comparison/entry.rb
97
118
  - lib/schema/validation/error.rb
98
119
  - lib/schema/validation/nil_attributes.rb
99
120
  homepage: https://github.com/eventide-project/schema
@@ -115,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
136
  - !ruby/object:Gem::Version
116
137
  version: '0'
117
138
  requirements: []
118
- rubygems_version: 3.0.1
139
+ rubygems_version: 3.1.2
119
140
  signing_key:
120
141
  specification_version: 4
121
142
  summary: Primitives for schema and data structure
@@ -1,26 +0,0 @@
1
- module Schema
2
- module Assertions
3
- def attributes_equal?(other, attributes=nil, print: nil)
4
- attributes ||= self.class.attribute_names
5
-
6
- print = true if print.nil?
7
- print ||= false
8
-
9
- equal = self.eql?(other, attributes, ignore_class: true)
10
-
11
- if !equal && print
12
- attributes = Array(attributes)
13
-
14
- require 'pp'
15
- puts "self: #{self.class.name}"
16
- pp self.attributes.select { |k, v| attributes.include? k }
17
- puts "other #{other.class.name}:"
18
- pp other.attributes.select { |k, v| attributes.include? k }
19
- puts "attributes:"
20
- attributes.each { |a| puts a.inspect}
21
- end
22
-
23
- equal
24
- end
25
- end
26
- end