parametric 0.2.12 → 0.2.13

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: c773dd859f56f8d526384567daf66c1c259a7e5d859c9fe40ecc620c0ee73253
4
- data.tar.gz: 9b056fd197e9fe84a2b14b16134d860ae3a7c49313f370fd9de82fb918c7bc3b
3
+ metadata.gz: 961d47f5a52e85cd54ea1aae3dde404423941e447896268370a360ba5cadf251
4
+ data.tar.gz: 006fbd9de033ab5d444e90f65ee81af5883ca380476e2de160bd700c9dc786ee
5
5
  SHA512:
6
- metadata.gz: 9d068ab0c811e30db11d3b6eea2e38937557d2abb36df07623f419b669e7186a86af8de645575cacdb5efe7a51c0dbbe40048aa3fe5417296ee3c5810fd477bf
7
- data.tar.gz: da9c1a990c6a0c2b85cf27d3f8ea7dd78e9b2e031548e240a79a43b85de9538e496ed491f3a5ef023ae6939d0f706b74274dd0519a7ae48d6452db65eed0d3ce
6
+ metadata.gz: 6a9b313400492d1f152ec94544ace651cdbbd91f579b3b99b668f06ea2c9861b8c0e80d1605e76f1b41a48aacd4d1e847fa840e60dbe34d9f88c8c6382371b01
7
+ data.tar.gz: 14e46b0e54fb309dd5be8fa1aeb10bf2363f7211bfae31e004135458f84319f4e38692e7322f988fe38228ddda8d1003f748c3bfb301510e694f32a5599e1c40
@@ -45,6 +45,15 @@ module Parametric
45
45
  policy sc.schema
46
46
  end
47
47
 
48
+ def from(another_field)
49
+ meta another_field.meta_data
50
+ another_field.policies.each do |plc|
51
+ policies << plc
52
+ end
53
+
54
+ self
55
+ end
56
+
48
57
  def visit(meta_key = nil, &visitor)
49
58
  if sc = meta_data[:schema]
50
59
  r = sc.visit(meta_key, &visitor)
@@ -85,8 +94,13 @@ module Parametric
85
94
  Result.new(eligible, value)
86
95
  end
87
96
 
97
+ protected
98
+
99
+ attr_reader :policies
100
+
88
101
  private
89
- attr_reader :policies, :registry, :default_block
102
+
103
+ attr_reader :registry, :default_block
90
104
 
91
105
  def resolve_one(policy, value, context)
92
106
  begin
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parametric
4
- VERSION = "0.2.12"
4
+ VERSION = "0.2.13"
5
5
  end
@@ -112,6 +112,20 @@ describe Parametric::Field do
112
112
  end
113
113
  end
114
114
 
115
+ describe '#from' do
116
+ it 'copies policies and metadata from an existing field' do
117
+ subject.policy(:string).present.options(['a', 'b', 'c'])
118
+
119
+ field = described_class.new(:another_key, registry).from(subject)
120
+ resolve(field, another_key: "abc").tap do |r|
121
+ has_errors
122
+ end
123
+ expect(field.meta_data[:type]).to eq(:string)
124
+ expect(field.meta_data[:present]).to be(true)
125
+ expect(field.meta_data[:options]).to eq(['a', 'b', 'c'])
126
+ end
127
+ end
128
+
115
129
  describe "#present" do
116
130
  it "is valid if value is present" do
117
131
  resolve(subject.present, a_key: "abc").tap do |r|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parametric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis