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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a4f53d13fdfe4476f9467127b58740f86b8f301979b56940eb9e228fd588225
4
- data.tar.gz: 5b26af44589c43bc2825a75e988318eefc3147581183a4c4cc65af5b98a47fed
3
+ metadata.gz: 61eb99562317fd43b8ea59c1ed4e48c13320ff04334d372c07b5c78efe7ebd22
4
+ data.tar.gz: ee09741be15edf7ff3082b285ae16549029e995eb5841518e7f4394f5c131049
5
5
  SHA512:
6
- metadata.gz: a5f7fbdfee4363b05e2044439499bd17954552b6a8c9b95442a613969e4775dcc2d05ee2340ba06df3b55b12df2414a16b672fe76c5b1ee2485ba6dede5cbdf7
7
- data.tar.gz: 9ea239bd608ef85e8f92a07060e10aff57b0552b92562b4e4ea1507e1a91a71173382565fd7f198d8f3a2595756b8a6badeb46638de14997fd15bf13250e4910
6
+ metadata.gz: 9c994b498b30870bb501890ecb44fe007d8ea49ae0ab2737033b70388ba36036b12a6795cf392a712e8b2d5121aa86e875280c080cf9a4ac4af953db2784c1fd
7
+ data.tar.gz: 55e8c26767574c8090d144465c23be6fe0a170470f736173cbde5beb059a8adcd1ca4aa52ad9a56038bc487b00e4595e7257d31ad84227df5720fe276c964012
@@ -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
@@ -61,5 +61,9 @@ module Parametric
61
61
  def key
62
62
  @policy.key
63
63
  end
64
+
65
+ def ==(other)
66
+ key == other.key && meta_data == other.meta_data
67
+ end
64
68
  end
65
69
  end
@@ -18,6 +18,10 @@ module Parametric
18
18
  @after_hooks = []
19
19
  end
20
20
 
21
+ def ==(other)
22
+ other.is_a?(Schema) && fields == other.fields
23
+ end
24
+
21
25
  def schema
22
26
  self
23
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parametric
4
- VERSION = '0.2.20'
4
+ VERSION = '0.2.21'
5
5
  end
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.20
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: 2023-12-11 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake