store_attribute 0.8.1 → 0.9.0
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 +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +6 -2
- data/lib/store_attribute/active_record/store.rb +29 -6
- data/lib/store_attribute/active_record/type/typed_store.rb +4 -0
- data/lib/store_attribute/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e666327899587f17df5c5196abd1f6094388d08c4ca4c020b9a67f182fa0660
|
|
4
|
+
data.tar.gz: 6a23e7d6122483843caaa7ae6d2da59e33e0c250c96306839bbb4cac8242ea87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b61d2f76d32c9ddbe3c993896a1826662b8afc881e7b72674ab21d8954e70dbae25630996ab920eeeb752436e433949bec36914d3b6a3278909ca85fce889de5
|
|
7
|
+
data.tar.gz: 07bb42459a9925b247b6cea363df401c4c9a92787bf6aca1de2bf795575e5895f331a0d4cd983e9b82ee1d27d0a35b47cd6a791314a756fcf78b438e8a25aea0
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## master
|
|
4
4
|
|
|
5
|
+
## 0.9.0 (2021-08-17) 📉
|
|
6
|
+
|
|
7
|
+
- Default values no longer marked as dirty. ([@markedmondson][])
|
|
8
|
+
|
|
5
9
|
## 0.8.1 (2020-12-03)
|
|
6
10
|
|
|
7
11
|
- Fix adding dirty tracking methods for `store_attribute`. ([@palkan][])
|
|
@@ -36,4 +40,5 @@
|
|
|
36
40
|
[@dreikanter]: https://github.com/dreikanter
|
|
37
41
|
[@SumLare]: https://github.com/SumLare
|
|
38
42
|
[@glaszig]: https://github.com/glaszig
|
|
39
|
-
[@ioki-klaus]: https://github.com/ioki-klaus
|
|
43
|
+
[@ioki-klaus]: https://github.com/ioki-klaus
|
|
44
|
+
[@markedmondson]: https://github.com/markedmondson
|
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://cultofmartians.com/tasks/store-attribute-defaults.html#task)
|
|
2
|
-
[](https://rubygems.org/gems/store_attribute)
|
|
2
|
+
[](https://rubygems.org/gems/store_attribute)
|
|
3
|
+

|
|
3
4
|
|
|
4
5
|
## Store Attribute
|
|
5
6
|
|
|
@@ -15,7 +16,7 @@ In your Gemfile:
|
|
|
15
16
|
|
|
16
17
|
```ruby
|
|
17
18
|
# for Rails 5+ (6 is supported)
|
|
18
|
-
gem "store_attribute", "~> 0.
|
|
19
|
+
gem "store_attribute", "~> 0.8.0"
|
|
19
20
|
|
|
20
21
|
# for Rails 4.2
|
|
21
22
|
gem "store_attribute", "~> 0.4.0"
|
|
@@ -48,6 +49,7 @@ class MegaUser < User
|
|
|
48
49
|
store_attribute :settings, :login_at, :datetime
|
|
49
50
|
store_attribute :settings, :active, :boolean
|
|
50
51
|
store_attribute :settings, :color, :string, default: "red"
|
|
52
|
+
store_attribute :settings, :colors, :json, default: ["red", "blue"]
|
|
51
53
|
store_attribute :settings, :data, :datetime, default: -> { Time.now }
|
|
52
54
|
end
|
|
53
55
|
|
|
@@ -59,6 +61,8 @@ u.ratio # => 63
|
|
|
59
61
|
u.active # => false
|
|
60
62
|
# Default value is set
|
|
61
63
|
u.color # => red
|
|
64
|
+
# Default array is set
|
|
65
|
+
u.colors # => ["red", "blue"]
|
|
62
66
|
# A dynamic default can also be provided
|
|
63
67
|
u.data # => Current time
|
|
64
68
|
# And we also have a predicate method
|
|
@@ -61,10 +61,29 @@ module ActiveRecord
|
|
|
61
61
|
|
|
62
62
|
_define_accessors_methods(store_name, *keys, prefix: accessor_prefix, suffix: accessor_suffix)
|
|
63
63
|
|
|
64
|
-
_define_dirty_tracking_methods(store_name, keys + typed_keys.keys, prefix: accessor_prefix, suffix: accessor_suffix)
|
|
65
|
-
|
|
66
64
|
_prepare_local_stored_attributes(store_name, *keys)
|
|
67
65
|
|
|
66
|
+
_store_accessors_module.module_eval do
|
|
67
|
+
define_method("changes") do
|
|
68
|
+
return @changes if defined?(@changes)
|
|
69
|
+
changes = super()
|
|
70
|
+
self.class.local_stored_attributes.each do |accessor, attributes|
|
|
71
|
+
next unless attribute_changed?(accessor)
|
|
72
|
+
|
|
73
|
+
prev_store, new_store = changes[accessor]
|
|
74
|
+
prev_store.each do |key, value|
|
|
75
|
+
if new_store[key] == value
|
|
76
|
+
changes[accessor][0].except!(key)
|
|
77
|
+
changes[accessor][1].except!(key)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
@changes = changes
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
_define_dirty_tracking_methods(store_name, keys + typed_keys.keys, prefix: accessor_prefix, suffix: accessor_suffix)
|
|
86
|
+
|
|
68
87
|
typed_keys.each do |key, type|
|
|
69
88
|
store_attribute(store_name, key, type, prefix: prefix, suffix: suffix)
|
|
70
89
|
end
|
|
@@ -128,11 +147,15 @@ module ActiveRecord
|
|
|
128
147
|
_define_predicate_method(name, prefix: prefix, suffix: suffix) if type == :boolean
|
|
129
148
|
|
|
130
149
|
# Rails >6.0
|
|
131
|
-
if method(:decorate_attribute_type).parameters.count { |type, _| type == :req } == 1
|
|
150
|
+
if !respond_to?(:decorate_attribute_type) || method(:decorate_attribute_type).parameters.count { |type, _| type == :req } == 1
|
|
132
151
|
attr_name = store_name.to_s
|
|
133
152
|
was_type = attributes_to_define_after_schema_loads[attr_name]&.first
|
|
134
153
|
attribute(attr_name) do |subtype|
|
|
135
|
-
|
|
154
|
+
if defined?(_lookup_cast_type)
|
|
155
|
+
Type::TypedStore.create_from_type(_lookup_cast_type(attr_name, was_type, {}), name, type, **options)
|
|
156
|
+
else
|
|
157
|
+
Type::TypedStore.create_from_type(subtype, name, type, **options)
|
|
158
|
+
end
|
|
136
159
|
end
|
|
137
160
|
else
|
|
138
161
|
decorate_attribute_type(store_name, "typed_accessor_for_#{name}") do |subtype|
|
|
@@ -140,9 +163,9 @@ module ActiveRecord
|
|
|
140
163
|
end
|
|
141
164
|
end
|
|
142
165
|
|
|
143
|
-
_define_dirty_tracking_methods(store_name, [name], prefix: prefix, suffix: suffix)
|
|
144
|
-
|
|
145
166
|
_prepare_local_stored_attributes(store_name, name)
|
|
167
|
+
|
|
168
|
+
_define_dirty_tracking_methods(store_name, [name], prefix: prefix, suffix: suffix)
|
|
146
169
|
end
|
|
147
170
|
|
|
148
171
|
def _prepare_local_stored_attributes(store_name, *keys) # :nodoc:
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: store_attribute
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- palkan
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -118,7 +118,7 @@ metadata:
|
|
|
118
118
|
documentation_uri: http://github.com/palkan/store_attribute
|
|
119
119
|
homepage_uri: http://github.com/palkan/store_attribute
|
|
120
120
|
source_code_uri: http://github.com/palkan/store_attribute
|
|
121
|
-
post_install_message:
|
|
121
|
+
post_install_message:
|
|
122
122
|
rdoc_options: []
|
|
123
123
|
require_paths:
|
|
124
124
|
- lib
|
|
@@ -133,8 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
133
133
|
- !ruby/object:Gem::Version
|
|
134
134
|
version: '0'
|
|
135
135
|
requirements: []
|
|
136
|
-
rubygems_version: 3.
|
|
137
|
-
signing_key:
|
|
136
|
+
rubygems_version: 3.2.15
|
|
137
|
+
signing_key:
|
|
138
138
|
specification_version: 4
|
|
139
139
|
summary: ActiveRecord extension which adds typecasting to store accessors
|
|
140
140
|
test_files: []
|