jsonb_accessor 1.0.0 → 1.3.2

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
- SHA1:
3
- metadata.gz: df479f24a7add99510b13cb3ef66aadae6c351f5
4
- data.tar.gz: e313ae7d2df70788f4786afab00ac7fc96d3268d
2
+ SHA256:
3
+ metadata.gz: 5b446e2b5fcf294a928c055c00334951830d068f7161437ec8fcab443cf2cee5
4
+ data.tar.gz: 443355750846f163a89307f662cd06d5034b5b922e7305209e8101b879f75b3e
5
5
  SHA512:
6
- metadata.gz: 7fb8c0e56ba54150d0e294eed76572bef85075ef003d5cda31c3d70b0a95bc845341e4f509831afe521623ce4e61cb23c0492caf6938fcb1e32e92da712eae70
7
- data.tar.gz: f21e03e8faf80523154bf119cf9b6d742bcc29337442ede7fa4ae69c95879e802af088218fa5b946bd08c35f38f4a0c6fcd3592c5223fdfe60d849875fcc5c3b
6
+ metadata.gz: 98019ca7f52229b5ca88a11b29ece4919bdd308a4c101dbc3a1b53ffa9d783ab90d9c09219be7ff7de37641a4545593851ed60da69cfc57dd53dfe6b7ee04238
7
+ data.tar.gz: 0e7b87df70bc3fdd71f4e384857970863b89bf60931c623b15b0983e554875cc1581672977bb274f0104fb393052d81447e05db4759826f83255d8cf03f355bd
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  gemfiles/.bundle
11
+ gemfiles/*.gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,11 +1,16 @@
1
1
  AllCops:
2
- Include:
3
- - "**/Rakefile"
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.7.2
4
+ SuggestExtensions: false
4
5
  Exclude:
5
- - db/**/*
6
- - gemfiles/**/*
7
- - vendor/**/*
8
- Style/SpaceBeforeFirstArg:
6
+ - "db/**/*"
7
+ - "gemfiles/**/*"
8
+ - "vendor/**/*"
9
+ Layout/SpaceBeforeFirstArg:
10
+ Enabled: false
11
+ Layout/LineLength:
12
+ Enabled: false
13
+ Layout/SpaceAroundEqualsInParameterDefault:
9
14
  Enabled: false
10
15
  Lint/UnusedBlockArgument:
11
16
  Enabled: false
@@ -17,8 +22,6 @@ Metrics/ClassLength:
17
22
  Enabled: false
18
23
  Metrics/CyclomaticComplexity:
19
24
  Enabled: false
20
- Metrics/LineLength:
21
- Enabled: false
22
25
  Metrics/MethodLength:
23
26
  Enabled: false
24
27
  Metrics/ModuleLength:
@@ -29,8 +32,6 @@ Metrics/BlockLength:
29
32
  Enabled: false
30
33
  Security/YAMLLoad:
31
34
  Enabled: false
32
- Style/AlignParameters:
33
- Enabled: false
34
35
  Style/ClassAndModuleChildren:
35
36
  Enabled: false
36
37
  Style/ClassVars:
@@ -39,25 +40,23 @@ Style/Documentation:
39
40
  Enabled: false
40
41
  Style/DoubleNegation:
41
42
  Enabled: false
42
- Style/FileName:
43
+ Naming/FileName:
43
44
  Enabled: false
44
45
  Style/GuardClause:
45
46
  Enabled: false
46
- Style/IndentHash:
47
- Enabled: false
48
47
  Style/NilComparison:
49
48
  Enabled: false
50
- Style/OpMethod:
51
- Enabled: false
52
49
  Style/RescueModifier:
53
50
  Enabled: false
54
51
  Style/SignalException:
55
52
  Enabled: false
56
53
  Style/SingleLineMethods:
57
54
  Enabled: false
58
- Style/SpaceAroundEqualsInParameterDefault:
59
- Enabled: false
60
55
  Style/StringLiterals:
61
56
  EnforcedStyle: double_quotes
62
- Performance/EndWith:
57
+ Naming/BinaryOperatorParameterName:
58
+ Enabled: false
59
+ Naming/VariableNumber:
60
+ Enabled: false
61
+ Gemspec/RequiredRubyVersion:
63
62
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.7.2
data/.travis.yml CHANGED
@@ -1,18 +1,30 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- - 2.3.3
5
- - 2.4.1
3
+ - 2.4.5
4
+ - 2.5.3
5
+ - 2.6.1
6
+ - 2.7.2
7
+ - 3.0.0
6
8
  addons:
7
- postgresql: '9.4'
9
+ postgresql: "9.4"
8
10
  before_install:
9
11
  - gem update --system
10
12
  - gem --version
11
- - gem install bundler
13
+ - gem install bundler:2.1.4
12
14
  before_script:
13
15
  - bundle exec rake db:create
14
16
  - bundle exec rake db:migrate
17
+ install: bundle _2.1.4_ install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
15
18
  cache: bundler
16
19
  gemfile:
17
20
  - gemfiles/activerecord_5.0.0.gemfile
18
21
  - gemfiles/activerecord_5.1.0.gemfile
22
+ - gemfiles/activerecord_6.1.0.gemfile
23
+ jobs:
24
+ exclude:
25
+ - rvm: 2.4.5
26
+ gemfile: gemfiles/activerecord_6.1.0.gemfile
27
+ - rvm: 3.0.0
28
+ gemfile: gemfiles/activerecord_5.0.0.gemfile
29
+ - rvm: 3.0.0
30
+ gemfile: gemfiles/activerecord_5.1.0.gemfile
data/Appraisals CHANGED
@@ -7,3 +7,7 @@ end
7
7
  appraise "activerecord-5.1.0" do
8
8
  gem "activerecord", "~> 5.1.3"
9
9
  end
10
+
11
+ appraise "activerecord-6.1.0" do
12
+ gem "activerecord", "~> 6.1"
13
+ end
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ ARG RUBY_VERSION=latest
2
+ FROM ruby:${RUBY_VERSION}
3
+
4
+ WORKDIR /usr/src/app
5
+
6
+ RUN mkdir -p lib/jsonb_accessor
7
+ COPY lib/jsonb_accessor/version.rb ./lib/jsonb_accessor/
8
+ COPY *.gemspec Gemfile* ./
9
+
10
+ RUN bundle install
11
+
12
+ COPY . .
data/README.md CHANGED
@@ -1,31 +1,31 @@
1
1
  # JSONb Accessor
2
2
 
3
- Created by &nbsp;&nbsp;&nbsp; [<img src="https://raw.githubusercontent.com/devmynd/jsonb_accessor/master/devmynd-logo.png" alt="DevMynd Logo" />](https://www.devmynd.com/)
3
+ Created by &nbsp;&nbsp;&nbsp; [<img src="https://raw.githubusercontent.com/madeintandem/jsonb_accessor/master/tandem-logo.png" alt="Tandem Logo" />](https://www.madeintandem.com/)
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/jsonb_accessor.svg)](http://badge.fury.io/rb/jsonb_accessor) &nbsp;&nbsp;&nbsp;[![Build Status](https://travis-ci.org/devmynd/jsonb_accessor.svg)](https://travis-ci.org/devmynd/jsonb_accessor) <img src="https://raw.githubusercontent.com/devmynd/jsonb_accessor/master/json-bee.png" alt="JSONb Accessor Logo" align="right" />
5
+ [![Gem Version](https://badge.fury.io/rb/jsonb_accessor.svg)](http://badge.fury.io/rb/jsonb_accessor) &nbsp;&nbsp;&nbsp;[![Build Status](https://travis-ci.org/madeintandem/jsonb_accessor.svg)](https://travis-ci.org/madeintandem/jsonb_accessor) <img src="https://raw.githubusercontent.com/madeintandem/jsonb_accessor/master/json-bee.png" alt="JSONb Accessor Logo" align="right" />
6
6
 
7
- Adds typed `jsonb` backed fields as first class citizens to your `ActiveRecord` models. This gem is similar in spirit to [HstoreAccessor](https://github.com/devmynd/hstore_accessor), but the `jsonb` column in PostgreSQL has a few distinct advantages, mostly around nested documents and support for collections.
7
+ Adds typed `jsonb` backed fields as first class citizens to your `ActiveRecord` models. This gem is similar in spirit to [HstoreAccessor](https://github.com/madeintandem/hstore_accessor), but the `jsonb` column in PostgreSQL has a few distinct advantages, mostly around nested documents and support for collections.
8
8
 
9
9
  It also adds generic scopes for querying `jsonb` columns.
10
10
 
11
11
  ## Table of Contents
12
12
 
13
- * [Installation](#installation)
14
- * [Usage](#usage)
15
- * [Scopes](#scopes)
16
- * [Single-Table Inheritance](#single-table-inheritance)
17
- * [Dependencies](#dependencies)
18
- * [Validations](#validations)
19
- * [Upgrading](#upgrading)
20
- * [Development](#development)
21
- * [Contributing](#contributing)
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [Scopes](#scopes)
16
+ - [Single-Table Inheritance](#single-table-inheritance)
17
+ - [Dependencies](#dependencies)
18
+ - [Validations](#validations)
19
+ - [Upgrading](#upgrading)
20
+ - [Development](#development)
21
+ - [Contributing](#contributing)
22
22
 
23
23
  ## Installation
24
24
 
25
25
  Add this line to your application's `Gemfile`:
26
26
 
27
27
  ```ruby
28
- gem "jsonb_accessor", "~> 1.0.0"
28
+ gem "jsonb_accessor", "~> 1"
29
29
  ```
30
30
 
31
31
  And then execute:
@@ -158,6 +158,7 @@ Product.all.jsonb_where(:data, reviewed_at: { before: Time.current }, p: { great
158
158
 
159
159
  Product.all.data_where(reviewed_at: { before: Time.current }, price: { greater_than: 5 })
160
160
  ```
161
+
161
162
  This scope makes use of the `jsonb_contains`, `jsonb_number_where`, and `jsonb_time_where` `scope`s.
162
163
 
163
164
  ### `jsonb_where_not`
@@ -219,14 +220,14 @@ Product.all.jsonb_number_where(:data, :price_in_cents, :greater_than, 300)
219
220
 
220
221
  It supports:
221
222
 
222
- * `>`
223
- * `>=`
224
- * `greater_than`
225
- * `greater_than_or_equal_to`
226
- * `<`
227
- * `<=`
228
- * `less_than`
229
- * `less_than_or_equal_to`
223
+ - `>`
224
+ - `>=`
225
+ - `greater_than`
226
+ - `greater_than_or_equal_to`
227
+ - `<`
228
+ - `<=`
229
+ - `less_than`
230
+ - `less_than_or_equal_to`
230
231
 
231
232
  and it is indifferent to strings/symbols.
232
233
 
@@ -259,9 +260,9 @@ Product.all.jsonb_time_where_not(:data, :reviewed_at, :before, 2.days.ago)
259
260
  ## Single-Table Inheritance
260
261
 
261
262
  One of the big issues with `ActiveRecord` single-table inheritance (STI)
262
- is sparse columns. Essentially, as sub-types of the original table
263
+ is sparse columns. Essentially, as sub-types of the original table
263
264
  diverge further from their parent more columns are left empty in a given
264
- table. Postgres' `jsonb` type provides part of the solution in that
265
+ table. Postgres' `jsonb` type provides part of the solution in that
265
266
  the values in an `jsonb` column does not impose a structure - different
266
267
  rows can have different values.
267
268
 
@@ -305,11 +306,11 @@ end
305
306
  ```
306
307
 
307
308
  From here any attributes specific to any sub-class can be stored in the
308
- `jsonb` column avoiding sparse data. Indices can also be created on
309
+ `jsonb` column avoiding sparse data. Indices can also be created on
309
310
  individual fields in an `jsonb` column.
310
311
 
311
312
  This approach was originally conceived by Joe Hirn in [this blog
312
- post](http://www.devmynd.com/blog/2013-3-single-table-inheritance-hstore-lovely-combination).
313
+ post](https://madeintandem.com/blog/2013-3-single-table-inheritance-hstore-lovely-combination/).
313
314
 
314
315
  ## Validations
315
316
 
@@ -326,15 +327,27 @@ See the [upgrade guide](UPGRADE_GUIDE.md).
326
327
 
327
328
  ## Development
328
329
 
330
+ ### On your local machine
331
+
329
332
  After checking out the repo, run `bin/setup` to install dependencies (make sure postgres is running first).
330
333
 
331
334
  Run `bin/console` for an interactive prompt that will allow you to experiment.
332
335
 
333
336
  `rake` will run Rubocop and the specs.
334
337
 
338
+ ### With Docker
339
+
340
+ ```
341
+ # setup
342
+ docker-compose build
343
+ docker-compose run ruby rake db:migrate
344
+ # run test suite
345
+ docker-compose run ruby rake spec
346
+ ```
347
+
335
348
  ## Contributing
336
349
 
337
- 1. [Fork it](https://github.com/devmynd/jsonb_accessor/fork)
350
+ 1. [Fork it](https://github.com/madeintandem/jsonb_accessor/fork)
338
351
  2. Create your feature branch (`git checkout -b my-new-feature`)
339
352
  3. Add tests and changes (run the tests with `rake`)
340
353
  4. Commit your changes (`git commit -am 'Add some feature'`)
data/Rakefile CHANGED
@@ -5,10 +5,29 @@ require "bundler/setup"
5
5
  require "bundler/gem_tasks"
6
6
  require "rspec/core/rake_task"
7
7
  require "rubocop/rake_task"
8
- require "standalone_migrations"
9
- StandaloneMigrations::Tasks.load_tasks
8
+ require "active_record"
9
+ require "erb"
10
10
 
11
11
  RSpec::Core::RakeTask.new
12
12
  RuboCop::RakeTask.new
13
13
 
14
+ # rubocop:disable Style/MixinUsage
15
+ include ActiveRecord::Tasks
16
+ # rubocop:enable Style/MixinUsage
17
+
18
+ root = File.expand_path __dir__
19
+ db_dir = File.join(root, "db")
20
+ DatabaseTasks.root = root
21
+ DatabaseTasks.db_dir = db_dir
22
+ DatabaseTasks.database_configuration = YAML.load(ERB.new(File.read(File.join(db_dir, "config.yml"))).result)
23
+ DatabaseTasks.migrations_paths = [File.join(db_dir, "migrate")]
24
+ DatabaseTasks.env = "test"
25
+
26
+ task :environment do
27
+ ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
28
+ ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym
29
+ end
30
+
31
+ load "active_record/railties/databases.rake"
32
+
14
33
  task(default: %i[rubocop spec])
data/bin/console CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # rubocop:disable Lint/UselessAssignment
5
-
6
4
  require "bundler/setup"
7
5
  require "jsonb_accessor"
8
6
  require "rspec"
9
- require File.expand_path("../../spec/spec_helper.rb", __FILE__)
7
+ require File.expand_path("../spec/spec_helper.rb", __dir__)
10
8
 
11
9
  dbconfig = YAML.load(File.open("db/config.yml"))
12
10
  ActiveRecord::Base.establish_connection(dbconfig["development"])
13
11
 
12
+ # rubocop:disable Lint/UselessAssignment
14
13
  x = Product.new
14
+ # rubocop:enable Lint/UselessAssignment
15
15
 
16
16
  Pry.start
data/db/config.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  default: &default
2
2
  adapter: postgresql
3
3
  database: jsonb_accessor
4
-
5
- development:
6
- <<: *default
4
+ host: <%= ENV.fetch("DATABASE_HOST") { "127.0.0.1" } %>
5
+ user: postgres
7
6
 
8
7
  test:
9
8
  <<: *default
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SetUpTestingDb < ActiveRecord::Migration[5.0]
2
4
  def change
3
5
  create_table :products do |t|
data/db/schema.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is auto-generated from the current state of the database. Instead
2
4
  # of editing this file, please use the migrations feature of Active Record to
3
5
  # incrementally modify your database, and then regenerate this schema definition.
@@ -10,8 +12,7 @@
10
12
  #
11
13
  # It's strongly recommended that you check this file into your version control system.
12
14
 
13
- ActiveRecord::Schema.define(version: 20150407031737) do
14
-
15
+ ActiveRecord::Schema.define(version: 20_150_407_031_737) do
15
16
  # These are extensions that must be enabled in order to support this database
16
17
  enable_extension "plpgsql"
17
18
 
@@ -32,5 +33,4 @@ ActiveRecord::Schema.define(version: 20150407031737) do
32
33
  t.datetime "datetime_type"
33
34
  t.decimal "decimal_type"
34
35
  end
35
-
36
36
  end
@@ -0,0 +1,26 @@
1
+ version: '3'
2
+
3
+ services:
4
+ ruby:
5
+ environment:
6
+ - DATABASE_HOST=postgres
7
+ build:
8
+ args:
9
+ - RUBY_VERSION=${RUBY_VERSION:-2.7.2}
10
+ context: .
11
+ volumes:
12
+ - '.:/usr/src/app'
13
+ depends_on:
14
+ - postgres
15
+
16
+ postgres:
17
+ image: postgres:12
18
+ environment:
19
+ - POSTGRES_HOST_AUTH_METHOD=trust
20
+ - POSTGRES_DB=jsonb_accessor
21
+ - PGDATA=/var/lib/postgresql/data/pgdata
22
+ volumes:
23
+ - pg_data:/var/lib/postgresql/data/pgdata
24
+
25
+ volumes:
26
+ pg_data:
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pg"
6
+ gem "activerecord", "~> 6.1"
7
+
8
+ gemspec path: "../"
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require "jsonb_accessor/version"
7
6
 
@@ -15,7 +14,7 @@ Gem::Specification.new do |spec|
15
14
  spec.description = "Adds typed jsonb backed fields to your ActiveRecord models."
16
15
  spec.homepage = "https://github.com/devmynd/jsonb_accessor"
17
16
  spec.license = "MIT"
18
- spec.required_ruby_version = "~> 2.0"
17
+ spec.required_ruby_version = ">= 2"
19
18
 
20
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.match(/png\z/) }
21
20
  spec.bindir = "exe"
@@ -27,14 +26,12 @@ Gem::Specification.new do |spec|
27
26
  spec.add_dependency "pg", ">= 0.18.1"
28
27
 
29
28
  spec.add_development_dependency "appraisal", "~> 2.2.0"
30
- spec.add_development_dependency "bundler", "~> 1.15.0"
31
- spec.add_development_dependency "database_cleaner", "~> 1.6.0"
32
29
  spec.add_development_dependency "awesome_print"
30
+ spec.add_development_dependency "database_cleaner", "~> 1.6.0"
33
31
  spec.add_development_dependency "pry"
34
32
  spec.add_development_dependency "pry-doc"
35
33
  spec.add_development_dependency "pry-nav"
36
- spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rake", ">= 12.3.3"
37
35
  spec.add_development_dependency "rspec", "~> 3.6.0"
38
- spec.add_development_dependency "rubocop", "~> 0.48.1"
39
- spec.add_development_dependency "standalone_migrations", "~> 5.2.0"
36
+ spec.add_development_dependency "rubocop", "~> 1"
40
37
  end
@@ -15,6 +15,6 @@ module JsonbAccessor
15
15
  end
16
16
 
17
17
  ActiveSupport.on_load(:active_record) do
18
- ActiveRecord::Base.send(:include, JsonbAccessor)
19
- ActiveRecord::Base.send(:include, JsonbAccessor::QueryBuilder)
18
+ ActiveRecord::Base.include JsonbAccessor
19
+ ActiveRecord::Base.include JsonbAccessor::QueryBuilder
20
20
  end
@@ -11,7 +11,11 @@ module JsonbAccessor
11
11
 
12
12
  # Defines virtual attributes for each jsonb field.
13
13
  field_types.each do |name, type|
14
- attribute name, *type
14
+ next attribute name, type unless type.is_a?(Array)
15
+ next attribute name, *type unless type.last.is_a?(Hash)
16
+
17
+ *args, keyword_args = type
18
+ attribute name, *args, **keyword_args
15
19
  end
16
20
 
17
21
  store_key_mapping_method_name = "jsonb_store_key_mapping_for_#{jsonb_attribute}"
@@ -51,7 +55,7 @@ module JsonbAccessor
51
55
  # each time it is evaluated.
52
56
  all_defaults_mapping_proc =
53
57
  if all_defaults_mapping.present?
54
- -> { all_defaults_mapping.map { |key, value| [key, value.respond_to?(:call) ? value.call : value] }.to_h }
58
+ -> { all_defaults_mapping.transform_values { |value| value.respond_to?(:call) ? value.call : value }.to_h.compact }
55
59
  end
56
60
  attribute jsonb_attribute, :jsonb, default: all_defaults_mapping_proc if all_defaults_mapping_proc.present?
57
61
 
@@ -67,17 +71,26 @@ module JsonbAccessor
67
71
  end
68
72
 
69
73
  # Overrides the jsonb attribute setter to make sure the jsonb fields are kept in sync.
70
- define_method("#{jsonb_attribute}=") do |given_value|
71
- value = given_value || {}
74
+ define_method("#{jsonb_attribute}=") do |value|
75
+ value ||= {}
72
76
  names_to_store_keys = self.class.public_send(store_key_mapping_method_name)
77
+ store_keys_to_names = names_to_store_keys.invert
73
78
 
74
- empty_store_key_attributes = names_to_store_keys.values.each_with_object({}) { |name, defaults| defaults[name] = nil }
75
- empty_named_attributes = names_to_store_keys.keys.each_with_object({}) { |name, defaults| defaults[name] = nil }
79
+ # this is the raw hash we want to save in the jsonb_attribute
80
+ value_with_store_keys = value.transform_keys do |k|
81
+ names_to_store_keys[k.to_s] || k
82
+ end
83
+ write_attribute(jsonb_attribute, value_with_store_keys)
76
84
 
77
- store_key_attributes = ::JsonbAccessor::QueryHelper.convert_keys_to_store_keys(value, names_to_store_keys)
78
- write_attribute(jsonb_attribute, empty_store_key_attributes.merge(store_key_attributes))
85
+ # this maps attributes to values
86
+ value_with_named_keys = value.transform_keys do |k|
87
+ store_keys_to_names[k.to_s] || k
88
+ end
79
89
 
80
- empty_named_attributes.merge(value).each { |name, attribute_value| write_attribute(name, attribute_value) }
90
+ empty_named_attributes = names_to_store_keys.transform_values { nil }
91
+ empty_named_attributes.merge(value_with_named_keys).each do |name, attribute_value|
92
+ write_attribute(name, attribute_value)
93
+ end
81
94
  end
82
95
  end
83
96
  include setters
@@ -88,9 +101,11 @@ module JsonbAccessor
88
101
  jsonb_values = public_send(jsonb_attribute) || {}
89
102
  jsonb_values.each do |store_key, value|
90
103
  name = names_and_store_keys.key(store_key)
91
- write_attribute(name, value) if name
104
+ next unless name
105
+
106
+ write_attribute(name, value)
107
+ clear_attribute_change(name) if persisted?
92
108
  end
93
- clear_changes_information if persisted?
94
109
  end
95
110
  end
96
111
 
@@ -61,9 +61,7 @@ module JsonbAccessor
61
61
  excludes_attributes = {}
62
62
 
63
63
  attributes.each do |name, value|
64
- if value.is_a?(Range)
65
- raise JsonbAccessor::QueryHelper::NotSupported, "`jsonb_where_not` scope does not accept ranges as arguments. Given `#{value}` for `#{name}` field"
66
- end
64
+ raise JsonbAccessor::QueryHelper::NotSupported, "`jsonb_where_not` scope does not accept ranges as arguments. Given `#{value}` for `#{name}` field" if value.is_a?(Range)
67
65
 
68
66
  if JsonbAccessor::QueryHelper.number_query_arguments?(value)
69
67
  value.each { |operator, query_value| query = query.jsonb_number_where_not(column_name, name, operator, query_value) }
@@ -81,7 +79,7 @@ module JsonbAccessor
81
79
  JsonbAccessor::QueryHelper.validate_column_name!(all, column_name)
82
80
  JsonbAccessor::QueryHelper.validate_field_name!(all, column_name, field_name)
83
81
  JsonbAccessor::QueryHelper.validate_direction!(direction)
84
- order("(#{table_name}.#{column_name} -> '#{field_name}') #{direction}")
82
+ order(Arel.sql("(#{table_name}.#{column_name} -> '#{field_name}') #{direction}"))
85
83
  end)
86
84
  end
87
85
  end
@@ -42,9 +42,7 @@ module JsonbAccessor
42
42
 
43
43
  class << self
44
44
  def validate_column_name!(query, column_name)
45
- if query.model.columns.none? { |column| column.name == column_name.to_s }
46
- raise InvalidColumnName, "a column named `#{column_name}` does not exist on the `#{query.model.table_name}` table"
47
- end
45
+ raise InvalidColumnName, "a column named `#{column_name}` does not exist on the `#{query.model.table_name}` table" if query.model.columns.none? { |column| column.name == column_name.to_s }
48
46
  end
49
47
 
50
48
  def validate_field_name!(query, column_name, field_name)
@@ -56,9 +54,7 @@ module JsonbAccessor
56
54
  end
57
55
 
58
56
  def validate_direction!(option)
59
- if ORDER_DIRECTIONS.exclude?(option)
60
- raise InvalidDirection, "`#{option}` is not a valid direction for ordering, only `asc` and `desc` are accepted"
61
- end
57
+ raise InvalidDirection, "`#{option}` is not a valid direction for ordering, only `asc` and `desc` are accepted" if ORDER_DIRECTIONS.exclude?(option)
62
58
  end
63
59
 
64
60
  def convert_keys_to_store_keys(attributes, store_key_mapping)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonbAccessor
4
- VERSION = "1.0.0"
4
+ VERSION = "1.3.2"
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonb_accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Crismali
8
8
  - Joe Hirn
9
9
  - Jason Haruska
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-08-26 00:00:00.000000000 Z
13
+ date: 2021-05-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -69,19 +69,19 @@ dependencies:
69
69
  - !ruby/object:Gem::Version
70
70
  version: 2.2.0
71
71
  - !ruby/object:Gem::Dependency
72
- name: bundler
72
+ name: awesome_print
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - "~>"
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: 1.15.0
77
+ version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - "~>"
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 1.15.0
84
+ version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: database_cleaner
87
87
  requirement: !ruby/object:Gem::Requirement
@@ -96,20 +96,6 @@ dependencies:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
98
  version: 1.6.0
99
- - !ruby/object:Gem::Dependency
100
- name: awesome_print
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
99
  - !ruby/object:Gem::Dependency
114
100
  name: pry
115
101
  requirement: !ruby/object:Gem::Requirement
@@ -156,16 +142,16 @@ dependencies:
156
142
  name: rake
157
143
  requirement: !ruby/object:Gem::Requirement
158
144
  requirements:
159
- - - "~>"
145
+ - - ">="
160
146
  - !ruby/object:Gem::Version
161
- version: '10.0'
147
+ version: 12.3.3
162
148
  type: :development
163
149
  prerelease: false
164
150
  version_requirements: !ruby/object:Gem::Requirement
165
151
  requirements:
166
- - - "~>"
152
+ - - ">="
167
153
  - !ruby/object:Gem::Version
168
- version: '10.0'
154
+ version: 12.3.3
169
155
  - !ruby/object:Gem::Dependency
170
156
  name: rspec
171
157
  requirement: !ruby/object:Gem::Requirement
@@ -186,28 +172,14 @@ dependencies:
186
172
  requirements:
187
173
  - - "~>"
188
174
  - !ruby/object:Gem::Version
189
- version: 0.48.1
190
- type: :development
191
- prerelease: false
192
- version_requirements: !ruby/object:Gem::Requirement
193
- requirements:
194
- - - "~>"
195
- - !ruby/object:Gem::Version
196
- version: 0.48.1
197
- - !ruby/object:Gem::Dependency
198
- name: standalone_migrations
199
- requirement: !ruby/object:Gem::Requirement
200
- requirements:
201
- - - "~>"
202
- - !ruby/object:Gem::Version
203
- version: 5.2.0
175
+ version: '1'
204
176
  type: :development
205
177
  prerelease: false
206
178
  version_requirements: !ruby/object:Gem::Requirement
207
179
  requirements:
208
180
  - - "~>"
209
181
  - !ruby/object:Gem::Version
210
- version: 5.2.0
182
+ version: '1'
211
183
  description: Adds typed jsonb backed fields to your ActiveRecord models.
212
184
  email:
213
185
  - michael@crismali.com
@@ -224,6 +196,7 @@ files:
224
196
  - ".travis.yml"
225
197
  - Appraisals
226
198
  - CODE_OF_CONDUCT.md
199
+ - Dockerfile
227
200
  - Gemfile
228
201
  - LICENSE.txt
229
202
  - README.md
@@ -234,10 +207,10 @@ files:
234
207
  - db/config.yml
235
208
  - db/migrate/20150407031737_set_up_testing_db.rb
236
209
  - db/schema.rb
210
+ - docker-compose.yml
237
211
  - gemfiles/activerecord_5.0.0.gemfile
238
- - gemfiles/activerecord_5.0.0.gemfile.lock
239
212
  - gemfiles/activerecord_5.1.0.gemfile
240
- - gemfiles/activerecord_5.1.0.gemfile.lock
213
+ - gemfiles/activerecord_6.1.0.gemfile
241
214
  - jsonb_accessor.gemspec
242
215
  - lib/jsonb_accessor.rb
243
216
  - lib/jsonb_accessor/macro.rb
@@ -248,24 +221,23 @@ homepage: https://github.com/devmynd/jsonb_accessor
248
221
  licenses:
249
222
  - MIT
250
223
  metadata: {}
251
- post_install_message:
224
+ post_install_message:
252
225
  rdoc_options: []
253
226
  require_paths:
254
227
  - lib
255
228
  required_ruby_version: !ruby/object:Gem::Requirement
256
229
  requirements:
257
- - - "~>"
230
+ - - ">="
258
231
  - !ruby/object:Gem::Version
259
- version: '2.0'
232
+ version: '2'
260
233
  required_rubygems_version: !ruby/object:Gem::Requirement
261
234
  requirements:
262
235
  - - ">="
263
236
  - !ruby/object:Gem::Version
264
237
  version: '0'
265
238
  requirements: []
266
- rubyforge_project:
267
- rubygems_version: 2.6.11
268
- signing_key:
239
+ rubygems_version: 3.1.4
240
+ signing_key:
269
241
  specification_version: 4
270
242
  summary: Adds typed jsonb backed fields to your ActiveRecord models.
271
243
  test_files: []
@@ -1,139 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- jsonb_accessor (1.0.0)
5
- activerecord (>= 5.0)
6
- activesupport (>= 5.0)
7
- pg (>= 0.18.1)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actionpack (5.0.5)
13
- actionview (= 5.0.5)
14
- activesupport (= 5.0.5)
15
- rack (~> 2.0)
16
- rack-test (~> 0.6.3)
17
- rails-dom-testing (~> 2.0)
18
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (5.0.5)
20
- activesupport (= 5.0.5)
21
- builder (~> 3.1)
22
- erubis (~> 2.7.0)
23
- rails-dom-testing (~> 2.0)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
- activemodel (5.0.5)
26
- activesupport (= 5.0.5)
27
- activerecord (5.0.5)
28
- activemodel (= 5.0.5)
29
- activesupport (= 5.0.5)
30
- arel (~> 7.0)
31
- activesupport (5.0.5)
32
- concurrent-ruby (~> 1.0, >= 1.0.2)
33
- i18n (~> 0.7)
34
- minitest (~> 5.1)
35
- tzinfo (~> 1.1)
36
- appraisal (2.2.0)
37
- bundler
38
- rake
39
- thor (>= 0.14.0)
40
- arel (7.1.4)
41
- ast (2.3.0)
42
- awesome_print (1.8.0)
43
- builder (3.2.3)
44
- coderay (1.1.1)
45
- concurrent-ruby (1.0.5)
46
- database_cleaner (1.6.1)
47
- diff-lcs (1.3)
48
- erubis (2.7.0)
49
- i18n (0.8.6)
50
- loofah (2.0.3)
51
- nokogiri (>= 1.5.9)
52
- method_source (0.8.2)
53
- mini_portile2 (2.2.0)
54
- minitest (5.10.3)
55
- nokogiri (1.8.0)
56
- mini_portile2 (~> 2.2.0)
57
- parser (2.4.0.0)
58
- ast (~> 2.2)
59
- pg (0.21.0)
60
- powerpack (0.1.1)
61
- pry (0.10.4)
62
- coderay (~> 1.1.0)
63
- method_source (~> 0.8.1)
64
- slop (~> 3.4)
65
- pry-doc (0.11.1)
66
- pry (~> 0.9)
67
- yard (~> 0.9)
68
- pry-nav (0.2.4)
69
- pry (>= 0.9.10, < 0.11.0)
70
- rack (2.0.3)
71
- rack-test (0.6.3)
72
- rack (>= 1.0)
73
- rails-dom-testing (2.0.3)
74
- activesupport (>= 4.2.0)
75
- nokogiri (>= 1.6)
76
- rails-html-sanitizer (1.0.3)
77
- loofah (~> 2.0)
78
- railties (5.0.5)
79
- actionpack (= 5.0.5)
80
- activesupport (= 5.0.5)
81
- method_source
82
- rake (>= 0.8.7)
83
- thor (>= 0.18.1, < 2.0)
84
- rainbow (2.2.2)
85
- rake
86
- rake (10.5.0)
87
- rspec (3.6.0)
88
- rspec-core (~> 3.6.0)
89
- rspec-expectations (~> 3.6.0)
90
- rspec-mocks (~> 3.6.0)
91
- rspec-core (3.6.0)
92
- rspec-support (~> 3.6.0)
93
- rspec-expectations (3.6.0)
94
- diff-lcs (>= 1.2.0, < 2.0)
95
- rspec-support (~> 3.6.0)
96
- rspec-mocks (3.6.0)
97
- diff-lcs (>= 1.2.0, < 2.0)
98
- rspec-support (~> 3.6.0)
99
- rspec-support (3.6.0)
100
- rubocop (0.48.1)
101
- parser (>= 2.3.3.1, < 3.0)
102
- powerpack (~> 0.1)
103
- rainbow (>= 1.99.1, < 3.0)
104
- ruby-progressbar (~> 1.7)
105
- unicode-display_width (~> 1.0, >= 1.0.1)
106
- ruby-progressbar (1.8.1)
107
- slop (3.6.0)
108
- standalone_migrations (5.2.3)
109
- activerecord (>= 4.2.7, < 5.2.0)
110
- railties (>= 4.2.7, < 5.2.0)
111
- rake (>= 10.0)
112
- thor (0.20.0)
113
- thread_safe (0.3.6)
114
- tzinfo (1.2.3)
115
- thread_safe (~> 0.1)
116
- unicode-display_width (1.3.0)
117
- yard (0.9.9)
118
-
119
- PLATFORMS
120
- ruby
121
-
122
- DEPENDENCIES
123
- activerecord (~> 5.0.0)
124
- appraisal (~> 2.2.0)
125
- awesome_print
126
- bundler (~> 1.15.0)
127
- database_cleaner (~> 1.6.0)
128
- jsonb_accessor!
129
- pg
130
- pry
131
- pry-doc
132
- pry-nav
133
- rake (~> 10.0)
134
- rspec (~> 3.6.0)
135
- rubocop (~> 0.48.1)
136
- standalone_migrations (~> 5.2.0)
137
-
138
- BUNDLED WITH
139
- 1.15.4
@@ -1,139 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- jsonb_accessor (1.0.0)
5
- activerecord (>= 5.0)
6
- activesupport (>= 5.0)
7
- pg (>= 0.18.1)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actionpack (5.1.3)
13
- actionview (= 5.1.3)
14
- activesupport (= 5.1.3)
15
- rack (~> 2.0)
16
- rack-test (~> 0.6.3)
17
- rails-dom-testing (~> 2.0)
18
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (5.1.3)
20
- activesupport (= 5.1.3)
21
- builder (~> 3.1)
22
- erubi (~> 1.4)
23
- rails-dom-testing (~> 2.0)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
- activemodel (5.1.3)
26
- activesupport (= 5.1.3)
27
- activerecord (5.1.3)
28
- activemodel (= 5.1.3)
29
- activesupport (= 5.1.3)
30
- arel (~> 8.0)
31
- activesupport (5.1.3)
32
- concurrent-ruby (~> 1.0, >= 1.0.2)
33
- i18n (~> 0.7)
34
- minitest (~> 5.1)
35
- tzinfo (~> 1.1)
36
- appraisal (2.2.0)
37
- bundler
38
- rake
39
- thor (>= 0.14.0)
40
- arel (8.0.0)
41
- ast (2.3.0)
42
- awesome_print (1.8.0)
43
- builder (3.2.3)
44
- coderay (1.1.1)
45
- concurrent-ruby (1.0.5)
46
- database_cleaner (1.6.1)
47
- diff-lcs (1.3)
48
- erubi (1.6.1)
49
- i18n (0.8.6)
50
- loofah (2.0.3)
51
- nokogiri (>= 1.5.9)
52
- method_source (0.8.2)
53
- mini_portile2 (2.2.0)
54
- minitest (5.10.3)
55
- nokogiri (1.8.0)
56
- mini_portile2 (~> 2.2.0)
57
- parser (2.4.0.0)
58
- ast (~> 2.2)
59
- pg (0.21.0)
60
- powerpack (0.1.1)
61
- pry (0.10.4)
62
- coderay (~> 1.1.0)
63
- method_source (~> 0.8.1)
64
- slop (~> 3.4)
65
- pry-doc (0.11.1)
66
- pry (~> 0.9)
67
- yard (~> 0.9)
68
- pry-nav (0.2.4)
69
- pry (>= 0.9.10, < 0.11.0)
70
- rack (2.0.3)
71
- rack-test (0.6.3)
72
- rack (>= 1.0)
73
- rails-dom-testing (2.0.3)
74
- activesupport (>= 4.2.0)
75
- nokogiri (>= 1.6)
76
- rails-html-sanitizer (1.0.3)
77
- loofah (~> 2.0)
78
- railties (5.1.3)
79
- actionpack (= 5.1.3)
80
- activesupport (= 5.1.3)
81
- method_source
82
- rake (>= 0.8.7)
83
- thor (>= 0.18.1, < 2.0)
84
- rainbow (2.2.2)
85
- rake
86
- rake (10.5.0)
87
- rspec (3.6.0)
88
- rspec-core (~> 3.6.0)
89
- rspec-expectations (~> 3.6.0)
90
- rspec-mocks (~> 3.6.0)
91
- rspec-core (3.6.0)
92
- rspec-support (~> 3.6.0)
93
- rspec-expectations (3.6.0)
94
- diff-lcs (>= 1.2.0, < 2.0)
95
- rspec-support (~> 3.6.0)
96
- rspec-mocks (3.6.0)
97
- diff-lcs (>= 1.2.0, < 2.0)
98
- rspec-support (~> 3.6.0)
99
- rspec-support (3.6.0)
100
- rubocop (0.48.1)
101
- parser (>= 2.3.3.1, < 3.0)
102
- powerpack (~> 0.1)
103
- rainbow (>= 1.99.1, < 3.0)
104
- ruby-progressbar (~> 1.7)
105
- unicode-display_width (~> 1.0, >= 1.0.1)
106
- ruby-progressbar (1.8.1)
107
- slop (3.6.0)
108
- standalone_migrations (5.2.3)
109
- activerecord (>= 4.2.7, < 5.2.0)
110
- railties (>= 4.2.7, < 5.2.0)
111
- rake (>= 10.0)
112
- thor (0.20.0)
113
- thread_safe (0.3.6)
114
- tzinfo (1.2.3)
115
- thread_safe (~> 0.1)
116
- unicode-display_width (1.3.0)
117
- yard (0.9.9)
118
-
119
- PLATFORMS
120
- ruby
121
-
122
- DEPENDENCIES
123
- activerecord (~> 5.1.3)
124
- appraisal (~> 2.2.0)
125
- awesome_print
126
- bundler (~> 1.15.0)
127
- database_cleaner (~> 1.6.0)
128
- jsonb_accessor!
129
- pg
130
- pry
131
- pry-doc
132
- pry-nav
133
- rake (~> 10.0)
134
- rspec (~> 3.6.0)
135
- rubocop (~> 0.48.1)
136
- standalone_migrations (~> 5.2.0)
137
-
138
- BUNDLED WITH
139
- 1.15.4