jsonb_accessor 1.4.1 → 1.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddb7db7a9ab5930ae31cac0fa871289638b0c5a3ba2f3486b4731a39e5d8f3aa
4
- data.tar.gz: 8c279fcfd16e6c5d490f31a45b0734f06fe70ee500c2a72cae1204d4d6a93e29
3
+ metadata.gz: 120f940dd7ef924ec2b795635444e5a4cb74f7f4a952684e0899d7d998af9166
4
+ data.tar.gz: 1e57e729d72bdd5eec71f9f037550df4667de8fd76d79452edd35eb57f673f9a
5
5
  SHA512:
6
- metadata.gz: 8a9b59f77d798b4e4134ccf5305a107bd220c89f1a377b7c6899273ba62c0c75ad697cb527c60f9a7a6e81dff52087c286cd8518859f00da4a2e8c37e3094531
7
- data.tar.gz: 733ee774842a1f4c2b734913fd1af2c02b43a892b27a955e64f44c46ca6bff93466436fd5e9d651e0ad081a09dc7d2a704302e6f5039b4db49e00d38544030f6
6
+ metadata.gz: 3c462840b6fc2ad2066ac098f4d5355f882f42ee8d03cbc36ee4981863a82458853597ace25804cb6b88666befae97d04d643276ee75753f1f277228f4ba0fe6
7
+ data.tar.gz: 8684c941ee588107771342c7fef94377f6f94c73b33d275d6deb6ea3cb56c304bf5b5c09c02b4a8880d3da9ad8eea5148e473ebf1705c92f29f0fb187ba95670
@@ -10,9 +10,9 @@ jobs:
10
10
  lint:
11
11
  runs-on: ubuntu-24.04
12
12
  steps:
13
- - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
13
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
14
14
 
15
- - uses: ruby/setup-ruby@80740b3b13bf9857e28854481ca95a84e78a2bdf # v1.284.0
15
+ - uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1.295.0
16
16
  with:
17
17
  ruby-version: "3.4"
18
18
  bundler-cache: true
@@ -53,14 +53,14 @@ jobs:
53
53
  ports: ['5432:5432']
54
54
  options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
55
55
  steps:
56
- - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
56
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
57
57
 
58
58
  - run: echo "gem 'activerecord', '~> ${{ matrix.activerecord }}.0'" > Gemfile.local
59
59
 
60
60
  - if: matrix.activerecord == '6.1' # see https://github.com/rails/rails/pull/54264#issuecomment-2596149819 and https://www.ruby-lang.org/en/news/2024/12/25/ruby-3-4-0-released/#standard-library-updates and https://www.ruby-lang.org/en/news/2025/12/25/ruby-4-0-0-released/#stdlib-updates
61
61
  run: printf "gem 'concurrent-ruby', '< 1.3.5'\ngem 'mutex_m'\ngem 'base64'\ngem 'bigdecimal'\ngem 'logger'\n" >> Gemfile.local
62
62
 
63
- - uses: ruby/setup-ruby@80740b3b13bf9857e28854481ca95a84e78a2bdf # v1.284.0
63
+ - uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1.295.0
64
64
  with:
65
65
  ruby-version: ${{ matrix.ruby }}
66
66
  bundler-cache: true
@@ -22,11 +22,11 @@ jobs:
22
22
  ruby: ["ruby-3.4", "jruby-9.4"]
23
23
 
24
24
  steps:
25
- - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
25
+ - uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
26
26
  with:
27
27
  egress-policy: audit
28
28
 
29
- - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
29
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
30
30
 
31
31
  - if: matrix.ruby == 'jruby-9.4' # cribbed from https://github.com/ruby/psych/blob/v5.2.4/.github/workflows/push_gem.yml
32
32
  run: |
@@ -35,9 +35,9 @@ jobs:
35
35
  gem install ruby-maven rake-compiler --no-document
36
36
  rake compile
37
37
 
38
- - uses: ruby/setup-ruby@80740b3b13bf9857e28854481ca95a84e78a2bdf # v1.284.0
38
+ - uses: ruby/setup-ruby@319994f95fa847cf3fb3cd3dbe89f6dcde9f178f # v1.295.0
39
39
  with:
40
40
  bundler-cache: true
41
41
  ruby-version: ${{ matrix.ruby }}
42
42
 
43
- - uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2
43
+ - uses: rubygems/release-gem@e9a6361a0b14562539327c2a02373edc56dd3169 # v1.1.4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
  ## [Unreleased]
3
3
 
4
+ ## [1.4.2] - 2026-03-20
5
+ ### Fixed
6
+ - Bug fix: Persisted records with sparse JSONB data returned `nil` instead of declared defaults for fields absent from the column. This regression was introduced in 1.4.1 during the `prefix`/`suffix` refactor, where `options.delete(:default)` mutated the options hash before passing it to `attribute`, stripping the default from the virtual attribute definition.
7
+
8
+ ### Changed
9
+ - Documented the backward-compatible positional hash syntax in `jsonb_accessor`, where definitions are passed as a plain hash (jsonb_accessor :col, { foo: :string })
10
+
4
11
  ## [1.4.1] - 2026-01-22
5
12
  ### Added
6
13
  - Support for `prefix` and `suffix` options to customize attribute accessor names while preserving original keys in the JSONB column. [#173](https://github.com/madeintandem/jsonb_accessor/issues/173)
@@ -24,7 +24,7 @@ module JsonbAccessor
24
24
  # <jsonb_attribute>_order scope
25
25
  klass.define_singleton_method "#{jsonb_attribute}_order" do |*args|
26
26
  ordering_options = args.extract_options!
27
- order_by_defaults = args.each_with_object({}) { |attribute, config| config[attribute] = :asc }
27
+ order_by_defaults = args.to_h { |attribute| [attribute, :asc] }
28
28
  store_key_mapping = all.model.public_send(store_key_mapping_method_name)
29
29
 
30
30
  order_by_defaults.merge(ordering_options).reduce(all) do |query, (name, direction)|
@@ -4,6 +4,10 @@ module JsonbAccessor
4
4
  module Macro
5
5
  module ClassMethods
6
6
  def jsonb_accessor(jsonb_attribute, global_options = {}, **definitions)
7
+ # Backward compatibility: support the old positional hash syntax where definitions
8
+ # are passed as a plain hash (jsonb_accessor :col, { foo: :string })
9
+ definitions = global_options if global_options.present? && definitions.blank?
10
+
7
11
  names_and_store_keys = {}
8
12
  names_and_defaults = {}
9
13
  names_and_attribute_names = {}
@@ -14,7 +18,7 @@ module JsonbAccessor
14
18
 
15
19
  # Determine store keys and default values for each field
16
20
  names_and_store_keys[name.to_s] = (options.delete(:store_key) || name).to_s
17
- names_and_defaults[name.to_s] = options.delete(:default) unless options[:default].nil?
21
+ names_and_defaults[name.to_s] = options[:default] unless options[:default].nil?
18
22
 
19
23
  prefix = options.delete(:prefix) || global_options[:prefix]
20
24
  suffix = options.delete(:suffix) || global_options[:suffix]
@@ -3,10 +3,10 @@
3
3
  module JsonbAccessor
4
4
  module QueryHelper
5
5
  # Errors
6
- InvalidColumnName = Class.new(StandardError)
7
- InvalidFieldName = Class.new(StandardError)
8
- InvalidDirection = Class.new(StandardError)
9
- NotSupported = Class.new(StandardError)
6
+ class InvalidColumnName < StandardError; end
7
+ class InvalidFieldName < StandardError; end
8
+ class InvalidDirection < StandardError; end
9
+ class NotSupported < StandardError; end
10
10
 
11
11
  # Constants
12
12
  GREATER_THAN = ">"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonbAccessor
4
- VERSION = "1.4.1"
4
+ VERSION = "1.4.2"
5
5
 
6
6
  def self.enum_support?
7
7
  # From AR 7.1 on, enums require a database column.
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.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Crismali