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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/deco_lite.gemspec +16 -1
- data/lib/deco_lite/hash_loadable.rb +2 -4
- data/lib/deco_lite/model.rb +2 -2
- data/lib/deco_lite/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beccc94d1fa8bec7ddba7ffbc0399eb37089d9e4379ca505536e91492f7b7f52
|
4
|
+
data.tar.gz: 6b4196a5605d7521bfc8554e7794acc4df7056dbbc05f14f8075ae3d2b0a19ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DecoLite
|
2
2
|
|
3
|
-
[![GitHub version](http://badge.fury.io/gh/gangelo%
|
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 =
|
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
|
-
|
25
|
-
|
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
|
data/lib/deco_lite/model.rb
CHANGED
@@ -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
|
data/lib/deco_lite/version.rb
CHANGED
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.
|
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-
|
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:
|
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: []
|