statinize 0.2.1 → 0.2.2

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: 7814eb5a73fe5fb67c846398c6d22573b183cafd88c243175ef4fb39c5f71fbe
4
- data.tar.gz: b7eec7d141ae6a0deda224802f67dae791ea7b9c96957922c9a7fa9c1b052e6a
3
+ metadata.gz: 1df88422c35ca62b3fe9b3efab22633e9f72a0e59690db7a005ae2cb9ad8cb4f
4
+ data.tar.gz: d72c1c0fdae71d168d082ee6e368970bdc81748cfa7ea293ec970065cd6232ef
5
5
  SHA512:
6
- metadata.gz: 8bea982ae518d67bb7f9c0a9cab47dd081d869dabbdf01874e14de5c2004217bd6f395e5e040f93499cbe5de413e1d3ed6b59222e9d8089cb6b01289748d1be9
7
- data.tar.gz: '08111b888a705bb74fe044f9de93ebcfd6863646df65510bf62e0566b23af1e4ef410609a22b0fc1afb1b15ffac62edbd9b43264a02191504e25296a99eab1e8'
6
+ metadata.gz: 21b6c73e849260241b4a2301bdbdf1663ceff7279b666564761818618728058be4e5e67dd9d6d11a1f7adc382468d8b5e7fdfcfaf67acbb3b294879a415d7a28
7
+ data.tar.gz: c984be3998b0e6a4ee7e0c4c57263a88f9c1c9698fc91487a499980353c5be9b6a72c2f94ba87cf95d543b9ef5418303e32b2b3edd8299163660cd4c629bae33
@@ -8,27 +8,32 @@ module Statinize
8
8
  end
9
9
 
10
10
  def attribute(*attrs, **options)
11
- options.merge!(@with) if @with
12
-
13
11
  attrs.each do |attr|
14
12
  Attribute.create(klass, attr, options)
15
13
  end
16
14
  end
17
15
 
18
16
  def validate(*attrs, **options)
19
- options.merge!(@with) if @with
20
-
21
17
  attrs.each do |attr|
22
18
  attribute = attributes.find { _1.name == attr }
23
19
  attribute&.add_options(options)
24
20
  end
25
21
  end
26
22
 
27
- def with(**kwargs, &block)
28
- @with = kwargs
29
- instance_exec(&block)
23
+ def with(**options, &block)
24
+ trace = TracePoint.trace(:call) do |tp|
25
+ tp.disable
26
+
27
+ if %i[attribute validate].include? tp.method_id
28
+ tp.binding.local_variable_get(:options).merge!(options)
29
+ end
30
30
 
31
- remove_instance_variable(:@with) if @with
31
+ tp.enable
32
+ end
33
+
34
+ trace.enable
35
+ instance_exec(&block)
36
+ trace.disable
32
37
  end
33
38
 
34
39
  def force(force = nil)
@@ -51,9 +51,10 @@ module Statinize
51
51
  force = option[:force] ||
52
52
  (statinizer.force? && option[:force].nil?)
53
53
 
54
- erroneous_attributes[attr.name].add option
54
+ if erroneous_attributes[attr.name].add? option
55
+ @errors << { attr.name => validator_instance.error }
56
+ end
55
57
  erroneous_forced_attributes[attr.name].add option if force
56
- @errors << { attr.name => validator_instance.error }
57
58
  end
58
59
  end
59
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statinize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barseek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Statinization gem. Allows for creation of attributes for a class with
14
14
  a given type.