parametric 0.2.13 → 0.2.16
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 +18 -1
- data/lib/parametric/struct.rb +4 -0
- data/lib/parametric/version.rb +1 -1
- data/spec/field_spec.rb +8 -0
- data/spec/struct_spec.rb +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f6f417ecf3ae9196ec9dc4757df98b21716c71ee43909e7f47a12d0885c983a
|
4
|
+
data.tar.gz: aae3258b0c564f98554a6de742aec9f25279c4352180c09b109add7587ab2977
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fffc57a0087500348370a0f4fe71744076eed77c9493e16638e21a457af66bc381865630bee84374c164b41909396e150e2e991480f97b2d8cac2017e512b84c
|
7
|
+
data.tar.gz: 8d24b5272d916ea58a1aa1f425d0261d948fe2c83957ec39a4156795de636f8c9a8e0e2fce1e166bb0a0f669c1ead5d864a65295b50ad7fb1f1d5077a450dc48
|
data/lib/parametric/field.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'delegate'
|
3
4
|
require "parametric/field_dsl"
|
4
5
|
|
5
6
|
module Parametric
|
@@ -54,6 +55,10 @@ module Parametric
|
|
54
55
|
self
|
55
56
|
end
|
56
57
|
|
58
|
+
def has_policy?(key)
|
59
|
+
policies.any? { |pol| pol.key == key }
|
60
|
+
end
|
61
|
+
|
57
62
|
def visit(meta_key = nil, &visitor)
|
58
63
|
if sc = meta_data[:schema]
|
59
64
|
r = sc.visit(meta_key, &visitor)
|
@@ -120,7 +125,19 @@ module Parametric
|
|
120
125
|
|
121
126
|
raise ConfigurationError, "No policies defined for #{key.inspect}" unless obj
|
122
127
|
|
123
|
-
obj
|
128
|
+
obj = obj.new(*args) if obj.respond_to?(:new)
|
129
|
+
obj = PolicyWithKey.new(obj, key)
|
130
|
+
|
131
|
+
obj
|
132
|
+
end
|
133
|
+
|
134
|
+
class PolicyWithKey < SimpleDelegator
|
135
|
+
attr_reader :key
|
136
|
+
|
137
|
+
def initialize(policy, key)
|
138
|
+
super policy
|
139
|
+
@key = key
|
140
|
+
end
|
124
141
|
end
|
125
142
|
end
|
126
143
|
end
|
data/lib/parametric/struct.rb
CHANGED
data/lib/parametric/version.rb
CHANGED
data/spec/field_spec.rb
CHANGED
@@ -88,6 +88,14 @@ describe Parametric::Field do
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
describe '#has_policy?' do
|
92
|
+
it 'is a boolean' do
|
93
|
+
subject.policy(:integer)
|
94
|
+
expect(subject.has_policy?(:integer)).to be(true)
|
95
|
+
expect(subject.has_policy?(:string)).to be(false)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
91
99
|
describe "#default" do
|
92
100
|
it "is default if missing key" do
|
93
101
|
resolve(subject.default("AA"), foobar: 1).tap do |r|
|
data/spec/struct_spec.rb
CHANGED
@@ -40,6 +40,10 @@ describe Parametric::Struct do
|
|
40
40
|
expect(instance.friends.first.name).to eq 'Ismael'
|
41
41
|
expect(instance.friends.first).to be_a friend_class
|
42
42
|
|
43
|
+
# Hash access with #[]
|
44
|
+
expect(instance[:title]).to eq instance.title
|
45
|
+
expect(instance[:friends].first[:name]).to eq instance.friends.first.name
|
46
|
+
|
43
47
|
invalid_instance = klass.new({
|
44
48
|
friends: [
|
45
49
|
{name: 'Ismael', age: 40},
|
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.16
|
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: 2022-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
116
|
+
rubygems_version: 3.2.32
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: DSL for declaring allowed parameters with options, regexp patern and default
|