jsonb_accessor 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f098f30fabf2c5bbbe39acaecc6487c84516837bb8f55ff1ecfcde0bdda24e2f
4
- data.tar.gz: 9dd89e98ec2937007ca3a11794ad3c0b3d48f8510a8f2836e0a1276b9ba8d5e0
3
+ metadata.gz: b3b40b7c775b9275c1fe7b6f3f3a8c0b7988dcd995da1b5bd594d0c3469ca372
4
+ data.tar.gz: 68dcf83030c07a537adee9030fd0f209f276e1e80f118c2d3ecc982694be466b
5
5
  SHA512:
6
- metadata.gz: 2f7ca35afa36d13d4907b7e81ccf9c380c9eba36d7a18c6b6a10a1dcc6e423096fd39ab7c69ef372d9a217a01f31530b271e2f5a72ed482be1faa4dcc43806ea
7
- data.tar.gz: 7389bebb7a9f7d6d4fcbde9cecc339f8505ae5cda68a6dbdd0489f10bcb1172919c9bd60d8bddee9be9a1053867ba99eefafce0be7cbf0022a151f9207fac069
6
+ metadata.gz: 9a136d5a27d25f8ffb29e2f2f06ffb43417b91544836dda70dd40583786512d29d302251c39eb877772e382da5ef4af28afc970a31ae295b5d01933d5f5e33bd
7
+ data.tar.gz: 411147569acaf3f9052e4ccae17063b3b0eaeb00c2738933a520a635861b054889b31b534b8959ae5d38bc3f5709dc0c3ccc9b20f45cf0f1f066b0aa60469e77
@@ -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::QueryHelper.convert_keys_to_store_keys(attributes, all.model.public_send(store_key_mapping_method_name))
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::QueryHelper.convert_keys_to_store_keys(attributes, all.model.public_send(store_key_mapping_method_name))
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
@@ -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::QueryHelper.convert_keys_to_store_keys(names_and_defaults, public_send(store_key_mapping_method_name))
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::QueryHelper.convert_keys_to_store_keys(value, names_to_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 = ::JsonbAccessor::QueryHelper.convert_store_keys_to_keys(value, names_to_store_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|
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonbAccessor
4
- VERSION = "1.3.3"
4
+ VERSION = "1.3.4"
5
5
  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.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-01-29 00:00:00.000000000 Z
13
+ date: 2022-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord