statinize 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/statinize/dsl.rb +7 -0
- data/lib/statinize/statinizer.rb +5 -4
- 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: b3184b7bdea5121e7355c91ad65b4929f9e3a13fcd6f6849a5bf971bb4f3ad3a
|
4
|
+
data.tar.gz: 6ab5f9e27b4a3f337dfb6fbffd018d847a25bf743df3788824f219668ea58650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 134c65ae58d093141b00c284367304951e5d7da83ba07a6dc0ababc35fd5fff4020fd6d6c7ce794bdb69095fa2bb6dcf53d3fdeb387c19e79c34e814c5a292c0
|
7
|
+
data.tar.gz: bbf362bb6cf6f87b190c4042f6897ad1b7c2ccf74ead7c6646dbc8bdf8e6d829e6503ca45806d306c6ccccd80b6b040b5a962e5ee9d5114a396bc7aa5e3959a1
|
data/lib/statinize/dsl.rb
CHANGED
@@ -16,15 +16,22 @@ module Statinize
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def with(**options, &block)
|
19
|
+
# create new statinizer instance
|
19
20
|
instance = self.class.new(klass)
|
20
21
|
instance.force(force)
|
21
22
|
|
23
|
+
# execute block in the context of that statinizer
|
24
|
+
# while it's attached to the klass
|
25
|
+
# then rewind and attach the original statinizer(self)
|
26
|
+
# back to the klass
|
22
27
|
klass.instance_variable_set(:@statinizer, instance)
|
23
28
|
instance.instance_exec(&block)
|
24
29
|
klass.instance_variable_set(:@statinizer, self)
|
25
30
|
|
31
|
+
# merge the newly created statinizer with the options
|
26
32
|
instance.merge_options(**options)
|
27
33
|
|
34
|
+
# populate self with the instance's attributes
|
28
35
|
populate(instance.attributes)
|
29
36
|
end
|
30
37
|
|
data/lib/statinize/statinizer.rb
CHANGED
@@ -50,10 +50,11 @@ module Statinize
|
|
50
50
|
|
51
51
|
def populate(attrs)
|
52
52
|
attrs.each do |attr|
|
53
|
-
attribute attr.name
|
54
|
-
attributes
|
55
|
-
.
|
56
|
-
.
|
53
|
+
attribute attr.arg_name, name: attr.name, default: attr.default
|
54
|
+
attributes.find { _1.name == attr.name }.tap do |attr_to_populate|
|
55
|
+
attr_to_populate.options_collection = attr.options_collection.clone
|
56
|
+
attr_to_populate.options = attr.options.clone
|
57
|
+
end
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
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.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barseek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-05 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.
|