deco_lite 1.2.0 → 1.3.0

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: 3025f7b914542580dcaaa18ab1666d0cabb4890e845b7155b1d98f5f917a1da5
4
- data.tar.gz: 597aa821f2edb7683cbd65b48561a64c2cdbbdb50457dae07f8d33e61aeeef1b
3
+ metadata.gz: beccc94d1fa8bec7ddba7ffbc0399eb37089d9e4379ca505536e91492f7b7f52
4
+ data.tar.gz: 6b4196a5605d7521bfc8554e7794acc4df7056dbbc05f14f8075ae3d2b0a19ae
5
5
  SHA512:
6
- metadata.gz: bd1786683a6f7a7ceaca9a9cd8bef861edd2d66e40416cb1bf67c75eda7e152f9d7d58ce96c0b4cdf6ae240c353cc9cbc1a5e0421379afb8d92b169a196527e5
7
- data.tar.gz: dbef72b83f45454fd2fa74e9bb94ad6079f45b9759a6729bb6b65e0b33ab657a8d9ea72545c0ffb9a2497310e68515b6bde8b25cc208876a5b0347ca9d65b3db
6
+ metadata.gz: c919d0514806dbe1acdea2bb9f544ee385587223a2a3f7cfeb4540c7995315fda1798ea6f15071f3e6a5fe41f4b3a2fb17faabbf67d8aaf0b7351cef1856846d
7
+ data.tar.gz: '0938c6d2069d7e094172fd8e710c44484be8a67638ee9cf234da6ab24e82c9d455f79bf5042a15576a86a28699be3412d3092b0169047c6d16811d9befcbe061'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ### 1.3.0
2
+ * Changes
3
+ * Update gem description in .gemspec.
4
+
5
+ ### 1.2.1
6
+ * Bugs
7
+ * Fix bug that did not recognize loaded field values if `attr_accessors` were previously created for the loaded fields due to model validations being present. If `ActiveModel` validators are present on the model, DecoLite will automatically create `attr_accessors` for the fields associated with the validations. The presence of these fields being automatically loaded prohibited any fields subsequently loaded having the same field names to not be recognized as having been loaded, causing validation to validate incorrectly (the model did not recognize the fields as having been loaded).
8
+ * Fix bug that wiped out field values previously loaded if `ActiveModel` validations were present for fields having the same name. This is because DecoLite will automatically create `attr_accessors` for the fields associated with the validations, initializing these automatically created field vars to be initialized to nil. The auto-creation of these `attr_accessors` was taking place in #initialize AFTER the initial load of any Hash passed to #initialize in the :hash param, so the values loaded were getting nilled out.
9
+ * Changes
10
+ * Add specs to test the above scenarios.
11
+
1
12
  ### 1.2.0
2
13
  * Changes
3
14
  * Update the README.md file with better explainations and examples.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deco_lite (1.2.0)
4
+ deco_lite (1.3.0)
5
5
  activemodel (~> 7.0, >= 7.0.3.1)
6
6
  activesupport (~> 7.0, >= 7.0.3.1)
7
7
  immutable_struct_ex (~> 0.2.0)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # DecoLite
2
2
 
3
- [![GitHub version](http://badge.fury.io/gh/gangelo%2Fdeco.svg)](https://badge.fury.io/gh/gangelo%2Fdeco_lite)
3
+ [![GitHub version](http://badge.fury.io/gh/gangelo%2Fdeco_lite.svg)](https://badge.fury.io/gh/gangelo%2Fdeco_lite)
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/deco_lite.svg)](https://badge.fury.io/rb/deco_lite)
6
6
 
@@ -136,7 +136,7 @@ wife = {
136
136
  },
137
137
  }
138
138
 
139
- class Couple < DecoLite::Model)
139
+ class Couple < DecoLite::Model
140
140
  def live_together?
141
141
  husband_info_address == wife_info_address
142
142
  end
data/deco_lite.gemspec CHANGED
@@ -11,7 +11,22 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['public.gma@gmail.com']
12
12
 
13
13
  spec.summary = 'Dynamically creates an active model from a Hash.'
14
- spec.description = 'Dynamically creates an active model from a Hash.'
14
+ spec.description = <<-EOF
15
+ DecoLite is a little gem that allows you to use the provided DecoLite::Model
16
+ class to dynamically create Decorator class objects. Use the DecoLite::Model
17
+ class directly, or inherit from the DecoLite::Model class to create your own
18
+ unique subclasses with custom functionality. DecoLite::Model
19
+ includes ActiveModel::Model, so validation can be applied using ActiveModel
20
+ validation helpers (https://api.rubyonrails.org/v6.1.3/classes/ActiveModel/Validations/HelperMethods.html)
21
+ you're familiar with; or, you can roll your own - just like any other ActiveModel.
22
+
23
+ DecoLite::Model allows you to consume a Ruby Hash that you supply via the
24
+ initializer (DecoLite::Model#new) or via the DecoLite::Model#load! method. Any
25
+ number of Ruby Hashes can be consumed. Your supplied Ruby Hashes are used to
26
+ create attr_accessor attributes (or "fields") on the model. Each attribute
27
+ created is then assigned the value from the Hash that was loaded. Again, any
28
+ number of hashes can be consumed using the DecoLite::Model#load! method.
29
+ EOF
15
30
  spec.homepage = 'https://github.com/gangelo/deco_lite'
16
31
  spec.license = 'MIT'
17
32
 
@@ -21,10 +21,8 @@ module DecoLite
21
21
  load_service.execute(hash: hash, options: load_service_options).tap do |service_hash|
22
22
  service_hash.each_pair do |field_name, value|
23
23
  create_field_accessor field_name: field_name, options: deco_lite_options
24
- unless field_names.include? field_name
25
- yield field_name if block_given?
26
- field_names << field_name
27
- end
24
+ yield field_name if block_given?
25
+ field_names << field_name unless field_names.include? field_name
28
26
  set_field_value(field_name: field_name, value: value, options: deco_lite_options)
29
27
  end
30
28
  end
@@ -34,9 +34,9 @@ module DecoLite
34
34
 
35
35
  hash ||= {}
36
36
 
37
- load_hash!(hash: hash, options: options) if hash.present?
38
-
39
37
  load_hash!(hash: auto_attr_accessors, options: options, add_loaded_fields: false) if auto_attr_accessors?
38
+
39
+ load_hash!(hash: hash, options: options) if hash.present?
40
40
  end
41
41
 
42
42
  validate :validate_required_fields
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the version of this gem.
4
4
  module DecoLite
5
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deco_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene M. Angelo, Jr.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-01 00:00:00.000000000 Z
11
+ date: 2022-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -234,7 +234,21 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: 13.0.6
237
- description: Dynamically creates an active model from a Hash.
237
+ description: |2
238
+ DecoLite is a little gem that allows you to use the provided DecoLite::Model
239
+ class to dynamically create Decorator class objects. Use the DecoLite::Model
240
+ class directly, or inherit from the DecoLite::Model class to create your own
241
+ unique subclasses with custom functionality. DecoLite::Model
242
+ includes ActiveModel::Model, so validation can be applied using ActiveModel
243
+ validation helpers (https://api.rubyonrails.org/v6.1.3/classes/ActiveModel/Validations/HelperMethods.html)
244
+ you're familiar with; or, you can roll your own - just like any other ActiveModel.
245
+
246
+ DecoLite::Model allows you to consume a Ruby Hash that you supply via the
247
+ initializer (DecoLite::Model#new) or via the DecoLite::Model#load! method. Any
248
+ number of Ruby Hashes can be consumed. Your supplied Ruby Hashes are used to
249
+ create attr_accessor attributes (or "fields") on the model. Each attribute
250
+ created is then assigned the value from the Hash that was loaded. Again, any
251
+ number of hashes can be consumed using the DecoLite::Model#load! method.
238
252
  email:
239
253
  - public.gma@gmail.com
240
254
  executables: []