serialize_attributes 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/serialize_attributes/store.rb +7 -1
- data/lib/serialize_attributes/version.rb +1 -1
- 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: 60ef1282c29e5ec4ae46242eed3dac95e756ddd5e6c57c95befc19a695bb9a6e
|
4
|
+
data.tar.gz: 9aa223ae50c2c60344844109bb4772a225796c7d70a0e7b355014bf765b402d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 867430cdb67e77c32ef2860fced5b004e80d3ac15300da02010addeff5d8100c0d20c84b0f8a80458041ad93896ccd0b86c8250dc3aad198e874eac9842f2bef
|
7
|
+
data.tar.gz: 5cebc02f04aa76e0d1dca6ecc9b63f645e595710d902d08a207eaf9d13fe11c6c5b6e51f9e52c3990340ada60d24bc1bd6bfdd189dd3137ce0652e8f88850964
|
data/README.md
CHANGED
@@ -63,6 +63,16 @@ record
|
|
63
63
|
#=> #<MyModel id: 1, settings: { user_name: "Nick", subscribed: true }>
|
64
64
|
```
|
65
65
|
|
66
|
+
Additionally you can use predicated methods the same way you do with an ActiveRecord's attribute.
|
67
|
+
Indeed behind the curtain we use `ActiveRecord::AttributeMethods::Query`.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
record.subscribed?
|
71
|
+
#=> false
|
72
|
+
record.user_name?
|
73
|
+
#=> true
|
74
|
+
```
|
75
|
+
|
66
76
|
### Getting all of the stored attributes
|
67
77
|
|
68
78
|
Default values are not automatically persisted to the database, so there is a helper
|
@@ -71,7 +71,7 @@ module SerializeAttributes
|
|
71
71
|
def deserialize(name, value)
|
72
72
|
attribute = @attributes[name.to_sym]
|
73
73
|
if attribute.nil?
|
74
|
-
raise "The attribute #{name} is not
|
74
|
+
raise "The attribute #{name} is not defined in serialize_attribute method in the #{@model_class} class."
|
75
75
|
end
|
76
76
|
|
77
77
|
attribute.deserialize(value)
|
@@ -142,6 +142,12 @@ module SerializeAttributes
|
|
142
142
|
end # end
|
143
143
|
end # end
|
144
144
|
#
|
145
|
+
unless #{array} # unless array
|
146
|
+
def #{name}? # def user_name?
|
147
|
+
query_attribute("#{name}") # query_attribute(:user_name)
|
148
|
+
end # end
|
149
|
+
end # end
|
150
|
+
#
|
145
151
|
def #{name}=(value) # def user_name=(value)
|
146
152
|
cast_value = self.class # cast_value = self.class
|
147
153
|
.serialized_attributes_store(:#{@column_name}) # .serialized_attributes_store(:settings)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serialize_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaikio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|