parametric 0.2.20 → 0.2.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parametric/field.rb +4 -0
- data/lib/parametric/policy_adapter.rb +4 -0
- data/lib/parametric/schema.rb +4 -0
- data/lib/parametric/version.rb +1 -1
- data/spec/field_spec.rb +18 -0
- data/spec/schema_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61eb99562317fd43b8ea59c1ed4e48c13320ff04334d372c07b5c78efe7ebd22
|
4
|
+
data.tar.gz: ee09741be15edf7ff3082b285ae16549029e995eb5841518e7f4394f5c131049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c994b498b30870bb501890ecb44fe007d8ea49ae0ab2737033b70388ba36036b12a6795cf392a712e8b2d5121aa86e875280c080cf9a4ac4af953db2784c1fd
|
7
|
+
data.tar.gz: 55e8c26767574c8090d144465c23be6fe0a170470f736173cbde5beb059a8adcd1ca4aa52ad9a56038bc487b00e4595e7257d31ad84227df5720fe276c964012
|
data/lib/parametric/field.rb
CHANGED
@@ -23,6 +23,10 @@ module Parametric
|
|
23
23
|
@policies = []
|
24
24
|
end
|
25
25
|
|
26
|
+
def ==(other)
|
27
|
+
other.is_a?(Field) && key == other.key && policies == other.policies && meta_data == other.meta_data
|
28
|
+
end
|
29
|
+
|
26
30
|
def meta(hash = nil)
|
27
31
|
@meta_data = @meta_data.merge(hash) if hash.is_a?(Hash)
|
28
32
|
self
|
data/lib/parametric/schema.rb
CHANGED
data/lib/parametric/version.rb
CHANGED
data/spec/field_spec.rb
CHANGED
@@ -59,6 +59,24 @@ describe Parametric::Field do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
describe '#==' do
|
63
|
+
it 'compares by key' do
|
64
|
+
field_a = described_class.new(:a_key, registry)
|
65
|
+
field_b = described_class.new(:a_key, registry)
|
66
|
+
field_c = described_class.new(:another_key, registry)
|
67
|
+
expect(field_a).to eq(field_b)
|
68
|
+
expect(field_a).not_to eq(field_c)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'compares by policies' do
|
72
|
+
field_a = described_class.new(:a_key, registry).type(:integer)
|
73
|
+
field_b = described_class.new(:a_key, registry).type(:integer)
|
74
|
+
field_c = described_class.new(:a_key, registry).type(:integer).options([1,2,3])
|
75
|
+
expect(field_a).to eq(field_b)
|
76
|
+
expect(field_a).not_to eq(field_c)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
describe "#policy" do
|
63
81
|
it "coerces integer" do
|
64
82
|
subject.policy(:integer)
|
data/spec/schema_spec.rb
CHANGED
@@ -46,6 +46,29 @@ describe Parametric::Schema do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
specify '#==' do
|
50
|
+
schema2 = described_class.new do
|
51
|
+
field(:title).policy(:string).present
|
52
|
+
field(:price).policy(:integer).meta(label: "A price")
|
53
|
+
field(:status).policy(:string).options(['visible', 'hidden'])
|
54
|
+
field(:tags).policy(:split).policy(:array)
|
55
|
+
field(:description).policy(:string)
|
56
|
+
field(:variants).policy(:array).schema do
|
57
|
+
field(:name).policy(:string).present
|
58
|
+
field(:sku)
|
59
|
+
field(:stock).policy(:integer).default(1)
|
60
|
+
field(:available_if_no_stock).policy(:boolean).policy(:flexible_bool).default(false)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
schema3 = described_class.new do
|
65
|
+
field(:title).policy(:string).present
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(subject).to eq schema2
|
69
|
+
expect(subject).not_to eq schema3
|
70
|
+
end
|
71
|
+
|
49
72
|
def resolve(schema, payload, &block)
|
50
73
|
yield schema.resolve(payload)
|
51
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parametric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|