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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 961d47f5a52e85cd54ea1aae3dde404423941e447896268370a360ba5cadf251
4
- data.tar.gz: 006fbd9de033ab5d444e90f65ee81af5883ca380476e2de160bd700c9dc786ee
3
+ metadata.gz: 2f6f417ecf3ae9196ec9dc4757df98b21716c71ee43909e7f47a12d0885c983a
4
+ data.tar.gz: aae3258b0c564f98554a6de742aec9f25279c4352180c09b109add7587ab2977
5
5
  SHA512:
6
- metadata.gz: 6a9b313400492d1f152ec94544ace651cdbbd91f579b3b99b668f06ea2c9861b8c0e80d1605e76f1b41a48aacd4d1e847fa840e60dbe34d9f88c8c6382371b01
7
- data.tar.gz: 14e46b0e54fb309dd5be8fa1aeb10bf2363f7211bfae31e004135458f84319f4e38692e7322f988fe38228ddda8d1003f748c3bfb301510e694f32a5599e1c40
6
+ metadata.gz: fffc57a0087500348370a0f4fe71744076eed77c9493e16638e21a457af66bc381865630bee84374c164b41909396e150e2e991480f97b2d8cac2017e512b84c
7
+ data.tar.gz: 8d24b5272d916ea58a1aa1f425d0261d948fe2c83957ec39a4156795de636f8c9a8e0e2fce1e166bb0a0f669c1ead5d864a65295b50ad7fb1f1d5077a450dc48
@@ -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.respond_to?(:new) ? obj.new(*args) : 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
@@ -38,6 +38,10 @@ module Parametric
38
38
  _results.output.clone
39
39
  end
40
40
 
41
+ def [](key)
42
+ _results.output[key.to_sym]
43
+ end
44
+
41
45
  def ==(other)
42
46
  other.respond_to?(:to_h) && other.to_h.eql?(to_h)
43
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parametric
4
- VERSION = "0.2.13"
4
+ VERSION = '0.2.16'
5
5
  end
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.13
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: 2020-08-24 00:00:00.000000000 Z
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.0.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