statinize 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9aab9a6ffd9f3b34b5275c2af057e44177f7881ce11fcea7ec4404a7cb933bad
4
- data.tar.gz: 8f71ae54ea17777a0440acdb966c6bc7dd59688184fe4af9b98c31d318fdcae5
3
+ metadata.gz: b3184b7bdea5121e7355c91ad65b4929f9e3a13fcd6f6849a5bf971bb4f3ad3a
4
+ data.tar.gz: 6ab5f9e27b4a3f337dfb6fbffd018d847a25bf743df3788824f219668ea58650
5
5
  SHA512:
6
- metadata.gz: 05b41cf02e7a4612e1ccc4e839df19733d33ee9e9e5d70296c0e5ce81a2bd5af51de2c0572b7791b284736538dd3e12a10a55f7c4a66872b3369ee628fd377df
7
- data.tar.gz: 697f7d67836e0057bbb8a9697e611fe026bb91276a02fea2367ec4f494a113d1ae2187b3cebc597070c540160773124e5d8cc192cc2cab213a8729713fca7053
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
 
@@ -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
- .find { _1.name == attr.name }
56
- .options_collection = attr.options_collection.clone
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.2
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-04 00:00:00.000000000 Z
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.