parametric 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parametric/schema.rb +9 -4
- data/lib/parametric/version.rb +1 -1
- data/spec/schema_spec.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef9d011c06f718caa4de95a60589cd858f693a98085a1962c8882e9213effd26
|
4
|
+
data.tar.gz: f759c6f6d051935a36d6a080b15602b628e4967b9b052d9ec3c5f912bf5a9b2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4867518fb179f164983751d2d6143a324eff9a961b91618e02677c74fe8e596f9f8d48a25582e2955c339f8128565b9cfaee95ca73f3a128a6b5861c5638aa
|
7
|
+
data.tar.gz: 87c47b5d47339b543027cff38b2f3a8a343ff27342ddfd1611fe0953c5b3169dee3064ac014a865382eebea0a87caab554312539f279648be43c66651c3a18b0
|
data/lib/parametric/schema.rb
CHANGED
@@ -44,11 +44,16 @@ module Parametric
|
|
44
44
|
copy_into instance
|
45
45
|
end
|
46
46
|
|
47
|
-
def merge(other_schema)
|
48
|
-
instance
|
47
|
+
def merge(other_schema = nil, &block)
|
48
|
+
raise ArgumentError, '#merge takes either a schema instance or a block' if other_schema.nil? && !block_given?
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
if other_schema
|
51
|
+
instance = self.class.new(options.merge(other_schema.options))
|
52
|
+
copy_into(instance)
|
53
|
+
other_schema.copy_into(instance)
|
54
|
+
else
|
55
|
+
merge(self.class.new(&block))
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
59
|
def copy_into(instance)
|
data/lib/parametric/version.rb
CHANGED
data/spec/schema_spec.rb
CHANGED
@@ -169,6 +169,17 @@ describe Parametric::Schema do
|
|
169
169
|
expect(new_schema.fields[:title].meta_data[:type]).to eq :string
|
170
170
|
expect(new_schema.fields[:price].meta_data[:type]).to eq :string
|
171
171
|
end
|
172
|
+
|
173
|
+
it 'can merge from a block' do
|
174
|
+
new_schema = schema1.merge do
|
175
|
+
field(:price).policy(:string)
|
176
|
+
field(:description).policy(:string)
|
177
|
+
end
|
178
|
+
|
179
|
+
expect(schema1.fields[:price].meta_data[:type]).to eq :integer
|
180
|
+
expect(new_schema.fields[:title].meta_data[:type]).to eq :string
|
181
|
+
expect(new_schema.fields[:price].meta_data[:type]).to eq :string
|
182
|
+
end
|
172
183
|
end
|
173
184
|
|
174
185
|
context "with options" do
|