statinize 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/statinize/statinizer.rb +13 -8
- data/lib/statinize/validation.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df88422c35ca62b3fe9b3efab22633e9f72a0e59690db7a005ae2cb9ad8cb4f
|
4
|
+
data.tar.gz: d72c1c0fdae71d168d082ee6e368970bdc81748cfa7ea293ec970065cd6232ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21b6c73e849260241b4a2301bdbdf1663ceff7279b666564761818618728058be4e5e67dd9d6d11a1f7adc382468d8b5e7fdfcfaf67acbb3b294879a415d7a28
|
7
|
+
data.tar.gz: c984be3998b0e6a4ee7e0c4c57263a88f9c1c9698fc91487a499980353c5be9b6a72c2f94ba87cf95d543b9ef5418303e32b2b3edd8299163660cd4c629bae33
|
data/lib/statinize/statinizer.rb
CHANGED
@@ -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(**
|
28
|
-
|
29
|
-
|
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
|
-
|
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)
|
data/lib/statinize/validation.rb
CHANGED
@@ -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.
|
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-
|
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.
|