jsonb_accessor 1.3.3 → 1.3.4
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 +14 -0
- data/CHANGELOG.md +5 -0
- data/lib/jsonb_accessor/attribute_query_methods.rb +2 -2
- data/lib/jsonb_accessor/helpers.rb +14 -0
- data/lib/jsonb_accessor/macro.rb +4 -4
- data/lib/jsonb_accessor/query_helper.rb +0 -12
- data/lib/jsonb_accessor/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: b3b40b7c775b9275c1fe7b6f3f3a8c0b7988dcd995da1b5bd594d0c3469ca372
|
4
|
+
data.tar.gz: 68dcf83030c07a537adee9030fd0f209f276e1e80f118c2d3ecc982694be466b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a136d5a27d25f8ffb29e2f2f06ffb43417b91544836dda70dd40583786512d29d302251c39eb877772e382da5ef4af28afc970a31ae295b5d01933d5f5e33bd
|
7
|
+
data.tar.gz: 411147569acaf3f9052e4ccae17063b3b0eaeb00c2738933a520a635861b054889b31b534b8959ae5d38bc3f5709dc0c3ccc9b20f45cf0f1f066b0aa60469e77
|
data/.github/workflows/ci.yml
CHANGED
@@ -7,7 +7,21 @@ on:
|
|
7
7
|
branches: ['**']
|
8
8
|
|
9
9
|
jobs:
|
10
|
+
lint:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.7.2
|
19
|
+
bundler-cache: true
|
20
|
+
- name: Rubocop
|
21
|
+
run: bundle exec rubocop
|
22
|
+
|
10
23
|
tests:
|
24
|
+
needs: lint
|
11
25
|
services:
|
12
26
|
db:
|
13
27
|
image: postgres:9.4
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
## [Unreleased]
|
3
3
|
|
4
|
+
## [1.3.4] - 2022-02-02
|
5
|
+
### Fixed
|
6
|
+
|
7
|
+
- Bug fix: Raised ActiveModel::MissingAttributeError when model was initialized without the jsonb_accessor field [#145](https://github.com/madeintandem/jsonb_accessor/issues/145)
|
8
|
+
|
4
9
|
## [1.3.3] - 2022-01-29
|
5
10
|
### Fixed
|
6
11
|
|
@@ -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 = ::JsonbAccessor::
|
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 = ::JsonbAccessor::
|
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
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module JsonbAccessor
|
2
4
|
module Helpers
|
3
5
|
module_function
|
@@ -5,5 +7,17 @@ module JsonbAccessor
|
|
5
7
|
def active_record_default_timezone
|
6
8
|
ActiveRecord.try(:default_timezone) || ActiveRecord::Base.default_timezone
|
7
9
|
end
|
10
|
+
|
11
|
+
# Replaces all keys in `attributes` that have a defined store_key with the store_key
|
12
|
+
def convert_keys_to_store_keys(attributes, store_key_mapping)
|
13
|
+
attributes.stringify_keys.transform_keys do |key|
|
14
|
+
store_key_mapping[key] || key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Replaces all keys in `attributes` that have a defined store_key with the named key (alias)
|
19
|
+
def convert_store_keys_to_keys(attributes, store_key_mapping)
|
20
|
+
convert_keys_to_store_keys(attributes, store_key_mapping.invert)
|
21
|
+
end
|
8
22
|
end
|
9
23
|
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 = ::JsonbAccessor::
|
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}"
|
@@ -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 = ::JsonbAccessor::
|
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 = ::JsonbAccessor::
|
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|
|
@@ -103,7 +103,7 @@ module JsonbAccessor
|
|
103
103
|
|
104
104
|
# Makes sure new objects have the appropriate values in their jsonb fields.
|
105
105
|
after_initialize do
|
106
|
-
next unless jsonb_attribute
|
106
|
+
next unless has_attribute? jsonb_attribute
|
107
107
|
|
108
108
|
jsonb_values = public_send(jsonb_attribute) || {}
|
109
109
|
jsonb_values.each do |store_key, value|
|
@@ -57,18 +57,6 @@ module JsonbAccessor
|
|
57
57
|
raise InvalidDirection, "`#{option}` is not a valid direction for ordering, only `asc` and `desc` are accepted" if ORDER_DIRECTIONS.exclude?(option)
|
58
58
|
end
|
59
59
|
|
60
|
-
# Replaces all keys in `attributes` that have a defined store_key with the store_key
|
61
|
-
def convert_keys_to_store_keys(attributes, store_key_mapping)
|
62
|
-
attributes.stringify_keys.transform_keys do |key|
|
63
|
-
store_key_mapping[key] || key
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Replaces all keys in `attributes` that have a defined store_key with the named key (alias)
|
68
|
-
def convert_store_keys_to_keys(attributes, store_key_mapping)
|
69
|
-
convert_keys_to_store_keys(attributes, store_key_mapping.invert)
|
70
|
-
end
|
71
|
-
|
72
60
|
def number_query_arguments?(arg)
|
73
61
|
arg.is_a?(Hash) && arg.keys.map(&:to_s).all? { |key| NUMBER_OPERATORS.include?(key) }
|
74
62
|
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.4
|
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-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|