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 +4 -4
- data/lib/parametric/field.rb +15 -1
- data/lib/parametric/version.rb +1 -1
- data/spec/field_spec.rb +14 -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: 961d47f5a52e85cd54ea1aae3dde404423941e447896268370a360ba5cadf251
|
4
|
+
data.tar.gz: 006fbd9de033ab5d444e90f65ee81af5883ca380476e2de160bd700c9dc786ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a9b313400492d1f152ec94544ace651cdbbd91f579b3b99b668f06ea2c9861b8c0e80d1605e76f1b41a48aacd4d1e847fa840e60dbe34d9f88c8c6382371b01
|
7
|
+
data.tar.gz: 14e46b0e54fb309dd5be8fa1aeb10bf2363f7211bfae31e004135458f84319f4e38692e7322f988fe38228ddda8d1003f748c3bfb301510e694f32a5599e1c40
|
data/lib/parametric/field.rb
CHANGED
@@ -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
|
-
|
102
|
+
|
103
|
+
attr_reader :registry, :default_block
|
90
104
|
|
91
105
|
def resolve_one(policy, value, context)
|
92
106
|
begin
|
data/lib/parametric/version.rb
CHANGED
data/spec/field_spec.rb
CHANGED
@@ -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|
|