jsonb_accessor 1.3.5 → 1.3.7
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/.github/workflows/ci.yml +62 -16
- data/Appraisals +8 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -3
- data/gemfiles/activerecord_5.0.0.gemfile +0 -1
- data/gemfiles/activerecord_5.1.0.gemfile +0 -1
- data/gemfiles/activerecord_5.2.0.gemfile +7 -0
- data/gemfiles/activerecord_6.0.0.gemfile +7 -0
- data/gemfiles/activerecord_6.1.0.gemfile +0 -1
- data/gemfiles/activerecord_7.0.1.gemfile +0 -1
- data/jsonb_accessor.gemspec +8 -1
- data/lib/jsonb_accessor/attribute_query_methods.rb +2 -2
- data/lib/jsonb_accessor/helpers.rb +14 -0
- data/lib/jsonb_accessor/macro.rb +9 -6
- data/lib/jsonb_accessor/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5a442265e4c3a26f2f725af683b94d3f6485688994c9c950852384e656ec81e
|
|
4
|
+
data.tar.gz: 9180a9f379d982c65ccb4e7b54df42e999b5001cc9b49c38aac7c24f0084b901
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 06e5645cc017da30a5b7452bc40d621a413429c66e2460a55db8dee76eb06424d7c5f64330f6aa909c93aa6b9d95d3b516ef4a877efbe3ef6310344fd2f3c01b
|
|
7
|
+
data.tar.gz: 1a1800490983e8013f8ba35cad25408ea3c50ca193b2f6ba49e290864fa485e4b9f9a87b810895c693be486714e4a6060e9396dc98fa5ead5096e325a1d7f150
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -38,49 +38,95 @@ jobs:
|
|
|
38
38
|
matrix:
|
|
39
39
|
include:
|
|
40
40
|
- gemfile: activerecord_5.0.0
|
|
41
|
-
ruby: 2.4
|
|
41
|
+
ruby: '2.4'
|
|
42
42
|
|
|
43
43
|
- gemfile: activerecord_5.1.0
|
|
44
|
-
ruby: 2.4
|
|
44
|
+
ruby: '2.4'
|
|
45
|
+
|
|
46
|
+
- gemfile: activerecord_5.2.0
|
|
47
|
+
ruby: '2.4'
|
|
45
48
|
|
|
46
49
|
- gemfile: activerecord_5.0.0
|
|
47
|
-
ruby: 2.5
|
|
50
|
+
ruby: '2.5'
|
|
48
51
|
|
|
49
52
|
- gemfile: activerecord_5.1.0
|
|
50
|
-
ruby: 2.5
|
|
53
|
+
ruby: '2.5'
|
|
54
|
+
|
|
55
|
+
- gemfile: activerecord_5.2.0
|
|
56
|
+
ruby: '2.5'
|
|
57
|
+
|
|
58
|
+
- gemfile: activerecord_6.0.0
|
|
59
|
+
ruby: '2.5'
|
|
51
60
|
|
|
52
61
|
- gemfile: activerecord_6.1.0
|
|
53
|
-
ruby: 2.5
|
|
62
|
+
ruby: '2.5'
|
|
54
63
|
|
|
55
64
|
- gemfile: activerecord_5.0.0
|
|
56
|
-
ruby: 2.6
|
|
65
|
+
ruby: '2.6'
|
|
57
66
|
|
|
58
67
|
- gemfile: activerecord_5.1.0
|
|
59
|
-
ruby: 2.6
|
|
68
|
+
ruby: '2.6'
|
|
69
|
+
|
|
70
|
+
- gemfile: activerecord_5.2.0
|
|
71
|
+
ruby: '2.6'
|
|
72
|
+
|
|
73
|
+
- gemfile: activerecord_6.0.0
|
|
74
|
+
ruby: '2.6'
|
|
60
75
|
|
|
61
76
|
- gemfile: activerecord_6.1.0
|
|
62
|
-
ruby: 2.6
|
|
77
|
+
ruby: '2.6'
|
|
63
78
|
|
|
64
79
|
- gemfile: activerecord_5.0.0
|
|
65
|
-
ruby: 2.7
|
|
80
|
+
ruby: '2.7'
|
|
66
81
|
|
|
67
82
|
- gemfile: activerecord_5.1.0
|
|
68
|
-
ruby: 2.7
|
|
83
|
+
ruby: '2.7'
|
|
84
|
+
|
|
85
|
+
- gemfile: activerecord_5.2.0
|
|
86
|
+
ruby: '2.7'
|
|
87
|
+
|
|
88
|
+
- gemfile: activerecord_6.0.0
|
|
89
|
+
ruby: '2.7'
|
|
69
90
|
|
|
70
91
|
- gemfile: activerecord_6.1.0
|
|
71
|
-
ruby: 2.7
|
|
92
|
+
ruby: '2.7'
|
|
72
93
|
|
|
73
94
|
- gemfile: activerecord_7.0.1
|
|
74
|
-
ruby: 2.7
|
|
95
|
+
ruby: '2.7'
|
|
96
|
+
|
|
97
|
+
- gemfile: activerecord_6.1.0
|
|
98
|
+
ruby: '3.0'
|
|
99
|
+
|
|
100
|
+
- gemfile: activerecord_6.1.0
|
|
101
|
+
ruby: '3.1'
|
|
75
102
|
|
|
76
103
|
- gemfile: activerecord_6.1.0
|
|
77
|
-
ruby: 3.
|
|
104
|
+
ruby: '3.2'
|
|
105
|
+
|
|
106
|
+
- gemfile: activerecord_7.0.1
|
|
107
|
+
ruby: '3.0'
|
|
78
108
|
|
|
79
109
|
- gemfile: activerecord_7.0.1
|
|
80
|
-
ruby: 3.
|
|
110
|
+
ruby: '3.1'
|
|
81
111
|
|
|
82
112
|
- gemfile: activerecord_7.0.1
|
|
83
|
-
ruby: 3.
|
|
113
|
+
ruby: '3.2'
|
|
114
|
+
|
|
115
|
+
- gemfile: activerecord_5.1.0
|
|
116
|
+
ruby: 'jruby-9.3'
|
|
117
|
+
|
|
118
|
+
- gemfile: activerecord_5.2.0
|
|
119
|
+
ruby: 'jruby-9.3'
|
|
120
|
+
|
|
121
|
+
- gemfile: activerecord_6.0.0
|
|
122
|
+
ruby: 'jruby-9.3'
|
|
123
|
+
|
|
124
|
+
- gemfile: activerecord_6.1.0
|
|
125
|
+
ruby: 'jruby-9.3'
|
|
126
|
+
|
|
127
|
+
# waiting for https://github.com/jruby/activerecord-jdbc-adapter/issues/1125 to be addressed
|
|
128
|
+
# - gemfile: activerecord_7.0.1
|
|
129
|
+
# ruby: 'jruby-9.4'
|
|
84
130
|
|
|
85
131
|
name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}
|
|
86
132
|
|
|
@@ -100,7 +146,7 @@ jobs:
|
|
|
100
146
|
|
|
101
147
|
- name: Setup DB
|
|
102
148
|
run: |
|
|
103
|
-
bundle exec rake db:
|
|
149
|
+
bundle exec rake db:schema:load
|
|
104
150
|
|
|
105
151
|
- name: Run tests
|
|
106
152
|
run: |
|
data/Appraisals
CHANGED
|
@@ -8,6 +8,14 @@ appraise "activerecord-5.1.0" do
|
|
|
8
8
|
gem "activerecord", "~> 5.1.3"
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
appraise "activerecord-5.2.0" do
|
|
12
|
+
gem "activerecord", "~> 5.2.8"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
appraise "activerecord-6.0.0" do
|
|
16
|
+
gem "activerecord", "~> 6.0.6"
|
|
17
|
+
end
|
|
18
|
+
|
|
11
19
|
appraise "activerecord-6.1.0" do
|
|
12
20
|
gem "activerecord", "~> 6.1"
|
|
13
21
|
end
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
## [Unreleased]
|
|
3
3
|
|
|
4
|
+
## [1.3.7] - 2022-12-29
|
|
5
|
+
|
|
6
|
+
- jruby support. jsonb_accessor now depends on `activerecord-jdbcpostgresql-adapter` instead of `pg` when the RUBY_PLATFORM is java. [#157](https://github.com/madeintandem/jsonb_accessor/pull/157)
|
|
7
|
+
|
|
8
|
+
## [1.3.6] - 2022-09-23
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Bug fix: Datetime values were not properly deserialized [#155](https://github.com/madeintandem/jsonb_accessor/pull/155)
|
|
12
|
+
|
|
4
13
|
## [1.3.5] - 2022-07-23
|
|
5
14
|
### Fixed
|
|
6
15
|
|
data/Gemfile
CHANGED
data/jsonb_accessor.gemspec
CHANGED
|
@@ -4,11 +4,14 @@ lib = File.expand_path("lib", __dir__)
|
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require "jsonb_accessor/version"
|
|
6
6
|
|
|
7
|
+
is_java = RUBY_PLATFORM == "java"
|
|
8
|
+
|
|
7
9
|
Gem::Specification.new do |spec|
|
|
8
10
|
spec.name = "jsonb_accessor"
|
|
9
11
|
spec.version = JsonbAccessor::VERSION
|
|
10
12
|
spec.authors = ["Michael Crismali", "Joe Hirn", "Jason Haruska"]
|
|
11
13
|
spec.email = ["michael@crismali.com", "joe@devmynd.com", "jason@haruska.com"]
|
|
14
|
+
spec.platform = "java" if is_java
|
|
12
15
|
|
|
13
16
|
spec.summary = "Adds typed jsonb backed fields to your ActiveRecord models."
|
|
14
17
|
spec.description = "Adds typed jsonb backed fields to your ActiveRecord models."
|
|
@@ -23,7 +26,11 @@ Gem::Specification.new do |spec|
|
|
|
23
26
|
|
|
24
27
|
spec.add_dependency "activerecord", ">= 5.0"
|
|
25
28
|
spec.add_dependency "activesupport", ">= 5.0"
|
|
26
|
-
|
|
29
|
+
if is_java
|
|
30
|
+
spec.add_dependency "activerecord-jdbcpostgresql-adapter", ">= 50.0"
|
|
31
|
+
else
|
|
32
|
+
spec.add_dependency "pg", ">= 0.18.1"
|
|
33
|
+
end
|
|
27
34
|
|
|
28
35
|
spec.add_development_dependency "appraisal", "~> 2.2.0"
|
|
29
36
|
spec.add_development_dependency "awesome_print"
|
|
@@ -11,13 +11,13 @@ module JsonbAccessor
|
|
|
11
11
|
|
|
12
12
|
# <jsonb_attribute>_where scope
|
|
13
13
|
klass.define_singleton_method "#{jsonb_attribute}_where" do |attributes|
|
|
14
|
-
store_key_attributes =
|
|
14
|
+
store_key_attributes = JsonbAccessor::Helpers.convert_keys_to_store_keys(attributes, all.model.public_send(store_key_mapping_method_name))
|
|
15
15
|
jsonb_where(jsonb_attribute, store_key_attributes)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# <jsonb_attribute>_where_not scope
|
|
19
19
|
klass.define_singleton_method "#{jsonb_attribute}_where_not" do |attributes|
|
|
20
|
-
store_key_attributes =
|
|
20
|
+
store_key_attributes = JsonbAccessor::Helpers.convert_keys_to_store_keys(attributes, all.model.public_send(store_key_mapping_method_name))
|
|
21
21
|
jsonb_where_not(jsonb_attribute, store_key_attributes)
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -19,5 +19,19 @@ module JsonbAccessor
|
|
|
19
19
|
def convert_store_keys_to_keys(attributes, store_key_mapping)
|
|
20
20
|
convert_keys_to_store_keys(attributes, store_key_mapping.invert)
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
def deserialize_value(value, attribute_type)
|
|
24
|
+
return value if value.blank?
|
|
25
|
+
|
|
26
|
+
if attribute_type == :datetime
|
|
27
|
+
value = if active_record_default_timezone == :utc
|
|
28
|
+
Time.find_zone("UTC").parse(value).in_time_zone
|
|
29
|
+
else
|
|
30
|
+
Time.zone.parse(value)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
value
|
|
35
|
+
end
|
|
22
36
|
end
|
|
23
37
|
end
|
data/lib/jsonb_accessor/macro.rb
CHANGED
|
@@ -38,7 +38,7 @@ module JsonbAccessor
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
# Get store keys to default values mapping
|
|
41
|
-
store_keys_and_defaults =
|
|
41
|
+
store_keys_and_defaults = JsonbAccessor::Helpers.convert_keys_to_store_keys(names_and_defaults, public_send(store_key_mapping_method_name))
|
|
42
42
|
|
|
43
43
|
# Define jsonb_defaults_mapping_for_<jsonb_attribute>
|
|
44
44
|
defaults_mapping_method_name = "jsonb_defaults_mapping_for_#{jsonb_attribute}"
|
|
@@ -69,7 +69,7 @@ module JsonbAccessor
|
|
|
69
69
|
attribute_value = public_send(name)
|
|
70
70
|
# Rails always saves time based on `default_timezone`. Since #as_json considers timezone, manual conversion is needed
|
|
71
71
|
if attribute_value.acts_like?(:time)
|
|
72
|
-
attribute_value = (
|
|
72
|
+
attribute_value = (JsonbAccessor::Helpers.active_record_default_timezone == :utc ? attribute_value.utc : attribute_value.in_time_zone).strftime("%F %R:%S.%L")
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
new_values = (public_send(jsonb_attribute) || {}).merge(store_key => attribute_value)
|
|
@@ -83,11 +83,11 @@ module JsonbAccessor
|
|
|
83
83
|
names_to_store_keys = self.class.public_send(store_key_mapping_method_name)
|
|
84
84
|
|
|
85
85
|
# this is the raw hash we want to save in the jsonb_attribute
|
|
86
|
-
value_with_store_keys =
|
|
86
|
+
value_with_store_keys = JsonbAccessor::Helpers.convert_keys_to_store_keys(value, names_to_store_keys)
|
|
87
87
|
write_attribute(jsonb_attribute, value_with_store_keys)
|
|
88
88
|
|
|
89
89
|
# this maps attributes to values
|
|
90
|
-
value_with_named_keys =
|
|
90
|
+
value_with_named_keys = JsonbAccessor::Helpers.convert_store_keys_to_keys(value, names_to_store_keys)
|
|
91
91
|
|
|
92
92
|
empty_named_attributes = names_to_store_keys.transform_values { nil }
|
|
93
93
|
empty_named_attributes.merge(value_with_named_keys).each do |name, attribute_value|
|
|
@@ -109,12 +109,15 @@ module JsonbAccessor
|
|
|
109
109
|
name = names_and_store_keys.key(store_key)
|
|
110
110
|
next unless name
|
|
111
111
|
|
|
112
|
-
write_attribute(
|
|
112
|
+
write_attribute(
|
|
113
|
+
name,
|
|
114
|
+
JsonbAccessor::Helpers.deserialize_value(value, self.class.type_for_attribute(name).type)
|
|
115
|
+
)
|
|
113
116
|
clear_attribute_change(name) if persisted?
|
|
114
117
|
end
|
|
115
118
|
end
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
JsonbAccessor::AttributeQueryMethods.new(self).define(store_key_mapping_method_name, jsonb_attribute)
|
|
118
121
|
end
|
|
119
122
|
end
|
|
120
123
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsonb_accessor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Crismali
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2022-
|
|
13
|
+
date: 2022-12-29 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activerecord
|
|
@@ -225,6 +225,8 @@ files:
|
|
|
225
225
|
- docker-compose.yml
|
|
226
226
|
- gemfiles/activerecord_5.0.0.gemfile
|
|
227
227
|
- gemfiles/activerecord_5.1.0.gemfile
|
|
228
|
+
- gemfiles/activerecord_5.2.0.gemfile
|
|
229
|
+
- gemfiles/activerecord_6.0.0.gemfile
|
|
228
230
|
- gemfiles/activerecord_6.1.0.gemfile
|
|
229
231
|
- gemfiles/activerecord_7.0.1.gemfile
|
|
230
232
|
- jsonb_accessor.gemspec
|