attr_json 1.0.0 → 1.1.0

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: 23ec569c6ce1f117952719d5ec18e8cd30f2e80a13d55eab307d37db26308c19
4
- data.tar.gz: bd676e6b2d8f606f1578cff495b4843e8722ca3f3dce2863226c59e7a716639b
3
+ metadata.gz: be1175039b6fbd78d5a9c1bcaae7c4ce003d29f403ef1e86d71d3c226e659a0b
4
+ data.tar.gz: 588710deb7c2b6076ba1cf1094f9b4ab67fb7bd74cecfc8c560de5b0ef50eafb
5
5
  SHA512:
6
- metadata.gz: c99101b1123256008aca96b8590a20906ca1650b1c70f82d24231043102296948070e2bcba78ec0c963e84c81f453b91bf82c2a0c7593f2ed57bc458365bf2f8
7
- data.tar.gz: 0fe8b60b2b96116b298c44b27ea044f97278eb66114d97cb6f00f868e1c60444bf6a23fecdeceb2a2f52ae670af3cfd809dd6065af3f9bd062df8373f4887897
6
+ metadata.gz: d71520892d16915465eab7c9e373f5e5ecabb8efee7a295da6532fbedd0c9817890da7e689e31f1bf1c7b3c1cad73f071f3563d7eb6d5637516de40174fce627
7
+ data.tar.gz: ea225c01754abfa5dec0e8749fd91ff68e1a329b54e684a27fee14655de7eb4eddf832538a961b14bbf83e222e0b90bfe554a8fdac001ca95aefb456353ed763
@@ -1,28 +1,64 @@
1
1
  #
2
- dist: trusty
3
2
  sudo: false
4
3
  addons:
5
4
  postgresql: '9.4'
6
5
  chrome: stable
7
6
  language: ruby
8
7
  cache: bundler
9
- rvm:
10
- - 2.4.5
11
- - 2.5.3
12
- gemfile:
13
- - gemfiles/rails_5_0.gemfile
14
- - gemfiles/rails_5_1.gemfile
15
- - gemfiles/rails_5_2.gemfile
16
- - gemfiles/rails_6_0.gemfile
17
- - gemfiles/rails_edge_6.gemfile
8
+
9
+ # rvm:
10
+ # - 2.4.5
11
+ # - 2.5.3
12
+ # - 2.6.5
13
+ # - 2.7.0
14
+ # gemfile:
15
+ # - gemfiles/rails_5_0.gemfile
16
+ # - gemfiles/rails_5_1.gemfile
17
+ # - gemfiles/rails_5_2.gemfile
18
+ # - gemfiles/rails_6_0.gemfile
19
+ # - gemfiles/rails_edge.gemfile
20
+
18
21
  before_install:
19
- - gem install bundler -v 1.14.6
22
+ - gem install bundler -v "~> 2.0"
23
+
20
24
  matrix:
25
+ include:
26
+ - rvm: 2.4.5
27
+ gemfile: gemfiles/rails_5_0.gemfile
28
+
29
+ - rvm: 2.4.5
30
+ gemfile: gemfiles/rails_5_1.gemfile
31
+
32
+ - rvm: 2.4.5
33
+ gemfile: gemfiles/rails_5_2.gemfile
34
+
35
+ - rvm: 2.5.3
36
+ gemfile: gemfiles/rails_5_0.gemfile
37
+
38
+ - rvm: 2.5.3
39
+ gemfile: gemfiles/rails_5_1.gemfile
40
+
41
+ - rvm: 2.5.3
42
+ gemfile: gemfiles/rails_5_2.gemfile
43
+
44
+ - rvm: 2.5.3
45
+ gemfile: gemfiles/rails_6_0.gemfile
46
+
47
+ - rvm: 2.6.5
48
+ gemfile: gemfiles/rails_5_2.gemfile
49
+
50
+ - rvm: 2.6.5
51
+ gemfile: gemfiles/rails_6_0.gemfile
52
+
53
+ - rvm: 2.7.0
54
+ gemfile: gemfiles/rails_6_0.gemfile
55
+
56
+ - rvm: 2.7.0
57
+ gemfile: gemfiles/rails_edge.gemfile
58
+
21
59
  allow_failures:
22
- - gemfile: gemfiles/rails_edge_6.gemfile
60
+ - gemfile: gemfiles/rails_edge.gemfile
23
61
  fast_finish: true
24
- exclude:
25
- - gemfile: gemfiles/rails_edge_6.gemfile
26
- rvm: 2.4.5
27
- - gemfile: gemfiles/rails_6_0.gemfile
28
- rvm: 2.4.5
62
+
63
+
64
+
data/Appraisals CHANGED
@@ -26,7 +26,7 @@ appraise "rails-5-2" do
26
26
  end
27
27
 
28
28
  appraise "rails-6-0" do
29
- gem 'combustion', git: "https://github.com/pat/combustion.git"
29
+ gem 'combustion', "~> 1.0"
30
30
 
31
31
  gem "rails", ">= 6.0.0.beta1", "< 6.1"
32
32
  gem "pg", "~> 1.0"
@@ -35,7 +35,7 @@ end
35
35
  appraise "rails-edge-6" do
36
36
  # Edge rails needs unreleased combustion
37
37
  # https://github.com/pat/combustion/issues/92
38
- gem 'combustion', git: "https://github.com/pat/combustion.git"
38
+ gem 'combustion', "~> 1.0"
39
39
 
40
40
  gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
41
41
  gem "pg", "~> 1.0"
@@ -4,5 +4,10 @@ Notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [Unreleased](https://github.com/jrochkind/attr_json/compare/v1.1.0...HEAD)
8
8
 
9
+ ## [1.1.0](https://github.com/jrochkind/attr_json/compare/v1.0.0...v1.1.0)
10
+
11
+ ### Added
12
+
13
+ * not_jsonb_contains query method, like `jsonb_contains` but negated. https://github.com/jrochkind/attr_json/pull/85
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ gemspec
10
10
  # We also have these development dependencies here in the Gemfile instead of the
11
11
  # gemspec so appraisal can override them from our Appraisal file.
12
12
 
13
- gem 'combustion', '~> 0.9.0'
13
+ gem 'combustion', '~> 1.1'
14
14
 
15
15
  # all of rails is NOT a dependency, just activerecord.
16
16
  # But we use it for integration testing with combustion. Hmm, a bit annoying
@@ -24,13 +24,13 @@ gem 'rails'
24
24
  gem 'railties'
25
25
 
26
26
  gem "pg"
27
- gem "rspec-rails", "~> 3.7"
27
+ gem "rspec-rails", "~> 4.0"
28
28
  gem "simple_form", ">= 4.0"
29
29
  gem 'cocoon', ">= 1.2"
30
30
  gem 'jquery-rails'
31
31
 
32
32
  gem 'capybara', "~> 3.0"
33
- gem 'webdrivers', '~> 3.0'
33
+ gem 'webdrivers', '~> 4.0'
34
34
  gem "selenium-webdriver"
35
35
 
36
36
  gem "byebug"
data/README.md CHANGED
@@ -138,6 +138,9 @@ MyModel.jsonb_contains(my_string: "foo", my_integer: 100).first
138
138
  # Implemented with scopes, this is an ordinary relation, you can
139
139
  # combine it with whatever, just like ordinary `where`.
140
140
 
141
+ MyModel.not_jsonb_contains(my:string: "foo", my_integer: 100).to_sql
142
+ # SELECT "products".* FROM "products" WHERE NOT (products.json_attributes @> ('{"my_string":"foo","my_integer":100}')::jsonb)
143
+
141
144
  # typecasts much like ActiveRecord on query too:
142
145
  MyModel.jsonb_contains(my_string: "foo", my_integer: "100")
143
146
  # no problem
@@ -48,7 +48,7 @@ attributes use as much of the existing ActiveRecord architecture as we can.}
48
48
  spec.add_runtime_dependency "activerecord", ">= 5.0.0", "< 6.1"
49
49
  end
50
50
 
51
- spec.add_development_dependency "bundler", "~> 1.14"
51
+ spec.add_development_dependency "bundler"
52
52
  spec.add_development_dependency "rake", ">= 10.0"
53
53
  spec.add_development_dependency "rspec", "~> 3.7"
54
54
  spec.add_development_dependency "database_cleaner", "~> 1.5"
@@ -6,12 +6,12 @@ gem "combustion", "~> 0.9.0"
6
6
  gem "rails", "~> 5.0.0"
7
7
  gem "railties"
8
8
  gem "pg", "~> 0.18"
9
- gem "rspec-rails", "~> 3.7"
9
+ gem "rspec-rails", "~> 4.0"
10
10
  gem "simple_form", ">= 4.0"
11
11
  gem "cocoon", ">= 1.2"
12
12
  gem "jquery-rails"
13
13
  gem "capybara", "~> 3.0"
14
- gem "webdrivers", "~> 3.0"
14
+ gem "webdrivers", "~> 4.0"
15
15
  gem "selenium-webdriver"
16
16
  gem "byebug"
17
17
  gem "rails-ujs", require: false
@@ -6,12 +6,12 @@ gem "combustion", "~> 0.9.0"
6
6
  gem "rails", "~> 5.1.0"
7
7
  gem "railties"
8
8
  gem "pg", "~> 1.0"
9
- gem "rspec-rails", "~> 3.7"
9
+ gem "rspec-rails", "~> 4.0"
10
10
  gem "simple_form", ">= 4.0"
11
11
  gem "cocoon", ">= 1.2"
12
12
  gem "jquery-rails"
13
13
  gem "capybara", "~> 3.0"
14
- gem "webdrivers", "~> 3.0"
14
+ gem "webdrivers", "~> 4.0"
15
15
  gem "selenium-webdriver"
16
16
  gem "byebug"
17
17
 
@@ -6,12 +6,12 @@ gem "combustion", "~> 0.9.0"
6
6
  gem "rails", "~> 5.2.0"
7
7
  gem "railties"
8
8
  gem "pg", "~> 1.0"
9
- gem "rspec-rails", "~> 3.7"
9
+ gem "rspec-rails", "~> 4.0"
10
10
  gem "simple_form", ">= 4.0"
11
11
  gem "cocoon", ">= 1.2"
12
12
  gem "jquery-rails"
13
13
  gem "capybara", "~> 3.0"
14
- gem "webdrivers", "~> 3.0"
14
+ gem "webdrivers", "~> 4.0"
15
15
  gem "selenium-webdriver"
16
16
  gem "byebug"
17
17
 
@@ -2,16 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "combustion", git: "https://github.com/pat/combustion.git"
5
+ gem "combustion", "~> 1.0"
6
6
  gem "rails", ">= 6.0.0.beta1", "< 6.1"
7
7
  gem "railties"
8
8
  gem "pg", "~> 1.0"
9
- gem "rspec-rails", "~> 3.7"
9
+ gem "rspec-rails", "~> 4.0"
10
10
  gem "simple_form", ">= 4.0"
11
11
  gem "cocoon", ">= 1.2"
12
12
  gem "jquery-rails"
13
13
  gem "capybara", "~> 3.0"
14
- gem "webdrivers", "~> 3.0"
14
+ gem "webdrivers", "~> 4.0"
15
15
  gem "selenium-webdriver"
16
16
  gem "byebug"
17
17
 
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "combustion", "~> 1.0"
6
+ gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
7
+ gem "railties"
8
+ gem "pg", "~> 1.0"
9
+ gem "rspec-rails", "~> 3.7"
10
+ gem "simple_form", ">= 4.0"
11
+ gem "cocoon", ">= 1.2"
12
+ gem "jquery-rails"
13
+ gem "capybara", "~> 3.0"
14
+ gem "webdrivers", "~> 4.0"
15
+ gem "selenium-webdriver"
16
+ gem "byebug"
17
+ gem "coffee-rails"
18
+
19
+ gemspec path: "../"
@@ -2,16 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "combustion", git: "https://github.com/pat/combustion.git"
5
+ gem "combustion", "~> 1.0"
6
6
  gem "rails", git: "https://github.com/rails/rails.git", branch: "master"
7
7
  gem "railties"
8
8
  gem "pg", "~> 1.0"
9
- gem "rspec-rails", "~> 3.7"
9
+ gem "rspec-rails", "~> 4.0"
10
10
  gem "simple_form", ">= 4.0"
11
11
  gem "cocoon", ">= 1.2"
12
12
  gem "jquery-rails"
13
13
  gem "capybara", "~> 3.0"
14
- gem "webdrivers", "~> 3.0"
14
+ gem "webdrivers", "~> 4.0"
15
15
  gem "selenium-webdriver"
16
16
  gem "byebug"
17
17
  gem "coffee-rails"
@@ -47,7 +47,7 @@ module AttrJson
47
47
  when false, nil, ActiveModel::Type::Boolean::FALSE_VALUES
48
48
  false
49
49
  else
50
- if value.respond_to?(:to_i) && ( Numeric === value || value !~ /[^0-9]/ )
50
+ if value.respond_to?(:to_i) && ( Numeric === value || value.to_s !~ /[^0-9]/ )
51
51
  !value.to_i.zero?
52
52
  elsif value.respond_to?(:zero?)
53
53
  !value.zero?
@@ -10,6 +10,20 @@ module AttrJson
10
10
  end
11
11
 
12
12
  def contains_relation
13
+ contains_relation_impl do |relation, query, params|
14
+ relation.where(query, params)
15
+ end
16
+ end
17
+
18
+ def contains_not_relation
19
+ contains_relation_impl do |relation, query, params|
20
+ relation.where.not(query, params)
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def contains_relation_impl
13
27
  result_relation = relation
14
28
 
15
29
  group_attributes_by_container.each do |container_attribute, attributes|
@@ -18,14 +32,12 @@ module AttrJson
18
32
  attributes.each do |key, value|
19
33
  add_to_param_hash!(param_hash, key, value)
20
34
  end
21
- result_relation = result_relation.where("#{relation.table_name}.#{container_attribute} @> (?)::jsonb", param_hash.to_json)
35
+ result_relation = yield(result_relation, "#{relation.table_name}.#{container_attribute} @> (?)::jsonb", param_hash.to_json)
22
36
  end
23
37
 
24
38
  result_relation
25
39
  end
26
40
 
27
- protected
28
-
29
41
  def merge_param_hash!(original, new)
30
42
  original.deep_merge!(new) do |key, old_val, new_val|
31
43
  if old_val.is_a?(Array) && old_val.first.is_a?(Hash) && new_val.is_a?(Array) && new_val.first.is_a?(Hash)
@@ -17,6 +17,8 @@ module AttrJson
17
17
  #
18
18
  # some_model.jsonb_contains(a_string: "foo").first
19
19
  #
20
+ # some_model.not_jsonb_contains(a_string: "bar").first
21
+ #
20
22
  # See more in {file:README} docs.
21
23
  module QueryScopes
22
24
  extend ActiveSupport::Concern
@@ -29,6 +31,10 @@ module AttrJson
29
31
  scope(:jsonb_contains, lambda do |attributes|
30
32
  QueryBuilder.new(self, attributes).contains_relation
31
33
  end)
34
+
35
+ scope(:not_jsonb_contains, lambda do |attributes|
36
+ QueryBuilder.new(self, attributes).contains_not_relation
37
+ end)
32
38
  end
33
39
  end
34
40
  end
@@ -51,6 +51,8 @@ module AttrJson
51
51
  # MyRecord.jsonb_contains(author: { name: "foo", type: "Corporation"})
52
52
  # MyRecord.jsonb_contains(author: Corporation.new(name: "foo"))
53
53
  #
54
+ # Additionally, there is not_jsonb_contains, which creates the same query terms like jsonb_contains, but negated.
55
+ #
54
56
  class PolymorphicModel < ActiveModel::Type::Value
55
57
  class TypeError < ::TypeError ; end
56
58
 
@@ -1,3 +1,3 @@
1
1
  module AttrJson
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -34,16 +34,16 @@ dependencies:
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.14'
39
+ version: '0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '1.14'
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -151,6 +151,7 @@ files:
151
151
  - gemfiles/rails_5_1.gemfile
152
152
  - gemfiles/rails_5_2.gemfile
153
153
  - gemfiles/rails_6_0.gemfile
154
+ - gemfiles/rails_edge.gemfile
154
155
  - gemfiles/rails_edge_6.gemfile
155
156
  - lib/attr_json.rb
156
157
  - lib/attr_json/attribute_definition.rb