graphiti 1.2.16 → 1.2.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +43 -14
- data/Appraisals +37 -5
- data/CHANGELOG.md +1 -1
- data/Gemfile +2 -0
- data/Guardfile +5 -5
- data/deprecated_generators/graphiti/resource_generator.rb +1 -1
- data/gemfiles/rails_5_0.gemfile +18 -0
- data/gemfiles/rails_5_0_graphiti_rails.gemfile +20 -0
- data/gemfiles/rails_5_1.gemfile +18 -0
- data/gemfiles/rails_5_1_graphiti_rails.gemfile +20 -0
- data/gemfiles/{rails_5.gemfile → rails_5_2.gemfile} +0 -0
- data/gemfiles/{rails_5_graphiti_rails.gemfile → rails_5_2_graphiti_rails.gemfile} +0 -0
- data/gemfiles/rails_6.gemfile +1 -1
- data/gemfiles/rails_6_graphiti_rails.gemfile +1 -1
- data/graphiti.gemspec +11 -12
- data/lib/graphiti.rb +3 -3
- data/lib/graphiti/adapters/abstract.rb +3 -3
- data/lib/graphiti/adapters/active_record.rb +65 -36
- data/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +2 -1
- data/lib/graphiti/configuration.rb +1 -1
- data/lib/graphiti/debugger.rb +12 -8
- data/lib/graphiti/delegates/pagination.rb +8 -4
- data/lib/graphiti/deserializer.rb +3 -3
- data/lib/graphiti/errors.rb +24 -4
- data/lib/graphiti/extensions/extra_attribute.rb +1 -1
- data/lib/graphiti/query.rb +32 -16
- data/lib/graphiti/railtie.rb +1 -1
- data/lib/graphiti/request_validator.rb +4 -4
- data/lib/graphiti/request_validators/update_validator.rb +1 -2
- data/lib/graphiti/request_validators/validator.rb +2 -2
- data/lib/graphiti/resource.rb +10 -0
- data/lib/graphiti/resource/configuration.rb +10 -3
- data/lib/graphiti/resource/dsl.rb +10 -4
- data/lib/graphiti/resource/interface.rb +2 -2
- data/lib/graphiti/resource/links.rb +3 -3
- data/lib/graphiti/resource/persistence.rb +2 -1
- data/lib/graphiti/resource/polymorphism.rb +2 -1
- data/lib/graphiti/resource/remote.rb +1 -1
- data/lib/graphiti/runner.rb +4 -3
- data/lib/graphiti/schema.rb +6 -6
- data/lib/graphiti/scope.rb +5 -5
- data/lib/graphiti/scoping/base.rb +3 -3
- data/lib/graphiti/scoping/filter.rb +17 -7
- data/lib/graphiti/scoping/sort.rb +1 -1
- data/lib/graphiti/serializer.rb +7 -0
- data/lib/graphiti/sideload.rb +30 -22
- data/lib/graphiti/sideload/belongs_to.rb +1 -1
- data/lib/graphiti/sideload/has_many.rb +19 -1
- data/lib/graphiti/sideload/many_to_many.rb +6 -2
- data/lib/graphiti/stats/payload.rb +4 -4
- data/lib/graphiti/types.rb +15 -15
- data/lib/graphiti/util/link.rb +6 -2
- data/lib/graphiti/util/persistence.rb +16 -10
- data/lib/graphiti/util/relationship_payload.rb +4 -4
- data/lib/graphiti/util/simple_errors.rb +1 -1
- data/lib/graphiti/util/transaction_hooks_recorder.rb +1 -1
- data/lib/graphiti/version.rb +1 -1
- metadata +18 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36b58f545ff99d459f7739072dd54045a8eee7f06990f7cee8450c1311788feb
|
4
|
+
data.tar.gz: bab55c98392e96c793b51bac6423c63b171782f36fddd3ef57531e4d3f280f9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9a8a3dce388ba6cec8100cbbd16c0c04e7aa0559acd2d3b028d00ce869537fce70c395e524c33351b4066142a48cecd3ee76bbf6c8d8b25e1fb38e997b0556
|
7
|
+
data.tar.gz: fbf3374a770546d24e62ebbc96091264f823ddeaaf99329eb0f51dfcfb918df999dcf6025aeb87868754671c079058e9a3e664db15c77cf6e00f1958a1b80ddd
|
data/.travis.yml
CHANGED
@@ -3,45 +3,74 @@ language: ruby
|
|
3
3
|
rvm:
|
4
4
|
- 2.5
|
5
5
|
- 2.6
|
6
|
+
- 2.7
|
6
7
|
gemfile:
|
7
8
|
- Gemfile
|
8
9
|
- gemfiles/rails_4.gemfile
|
9
|
-
- gemfiles/
|
10
|
+
- gemfiles/rails_5_0.gemfile
|
11
|
+
- gemfiles/rails_5_1.gemfile
|
12
|
+
- gemfiles/rails_5_2.gemfile
|
10
13
|
- gemfiles/rails_6.gemfile
|
11
|
-
- gemfiles/
|
14
|
+
- gemfiles/rails_5_0_graphiti_rails.gemfile
|
15
|
+
- gemfiles/rails_5_1_graphiti_rails.gemfile
|
16
|
+
- gemfiles/rails_5_2_graphiti_rails.gemfile
|
12
17
|
- gemfiles/rails_6_graphiti_rails.gemfile
|
13
18
|
env:
|
14
|
-
- COMMAND=standardrb --no-fix --format progress
|
19
|
+
- COMMAND="standardrb --no-fix --format progress"
|
15
20
|
- COMMAND=rspec
|
16
21
|
- COMMAND=rspec APPRAISAL_INITIALIZED=true
|
17
22
|
matrix:
|
18
23
|
exclude:
|
19
|
-
|
24
|
+
# Don't run the appraisal version of the specs for the base gemfile
|
25
|
+
- env: COMMAND=rspec APPRAISAL_INITIALIZED=true
|
26
|
+
gemfile: Gemfile
|
27
|
+
# Don't run the standardrb check on any gemfile except the base gemfile
|
28
|
+
# (but run it for each ruby version)
|
29
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
20
30
|
gemfile: gemfiles/rails_4.gemfile
|
21
|
-
- env: COMMAND=standardrb --no-fix --format progress
|
22
|
-
gemfile: gemfiles/
|
23
|
-
- env: COMMAND=standardrb --no-fix --format progress
|
31
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
32
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
33
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
34
|
+
gemfile: gemfiles/rails_5_1.gemfile
|
35
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
36
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
37
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
24
38
|
gemfile: gemfiles/rails_6.gemfile
|
25
|
-
- env: COMMAND=standardrb --no-fix --format progress
|
26
|
-
gemfile: gemfiles/
|
27
|
-
- env: COMMAND=standardrb --no-fix --format progress
|
39
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
40
|
+
gemfile: gemfiles/rails_5_0_graphiti_rails.gemfile
|
41
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
42
|
+
gemfile: gemfiles/rails_5_1_graphiti_rails.gemfile
|
43
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
44
|
+
gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
|
45
|
+
- env: COMMAND="standardrb --no-fix --format progress"
|
28
46
|
gemfile: gemfiles/rails_6_graphiti_rails.gemfile
|
29
|
-
|
30
|
-
gemfile: Gemfile
|
47
|
+
# Don't run the basic versions of the specs for any of the specific gemfiles
|
31
48
|
- env: COMMAND=rspec
|
32
49
|
gemfile: gemfiles/rails_4.gemfile
|
33
50
|
- env: COMMAND=rspec
|
34
|
-
gemfile: gemfiles/
|
51
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
52
|
+
- env: COMMAND=rspec
|
53
|
+
gemfile: gemfiles/rails_5_1.gemfile
|
54
|
+
- env: COMMAND=rspec
|
55
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
35
56
|
- env: COMMAND=rspec
|
36
57
|
gemfile: gemfiles/rails_6.gemfile
|
37
58
|
- env: COMMAND=rspec
|
38
|
-
gemfile: gemfiles/
|
59
|
+
gemfile: gemfiles/rails_5_0_graphiti_rails.gemfile
|
60
|
+
- env: COMMAND=rspec
|
61
|
+
gemfile: gemfiles/rails_5_1_graphiti_rails.gemfile
|
62
|
+
- env: COMMAND=rspec
|
63
|
+
gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
|
39
64
|
- env: COMMAND=rspec
|
40
65
|
gemfile: gemfiles/rails_6_graphiti_rails.gemfile
|
66
|
+
|
67
|
+
# Don't run rails 4 egmfile against any rubies (for some reason?)
|
41
68
|
- gemfile: gemfiles/rails_4.gemfile
|
42
69
|
rvm: 2.5
|
43
70
|
- gemfile: gemfiles/rails_4.gemfile
|
44
71
|
rvm: 2.6
|
72
|
+
- gemfile: gemfiles/rails_4.gemfile
|
73
|
+
rvm: 2.7
|
45
74
|
|
46
75
|
script:
|
47
76
|
- bundle _1.17.3_ exec $COMMAND
|
data/Appraisals
CHANGED
@@ -1,18 +1,50 @@
|
|
1
1
|
appraise "rails-4" do
|
2
|
-
gem "rails", "~> 4.
|
2
|
+
gem "rails", "~> 4.2"
|
3
3
|
gem "rspec-rails"
|
4
4
|
gem "sqlite3", "~> 1.3.6"
|
5
5
|
gem "database_cleaner"
|
6
6
|
end
|
7
7
|
|
8
|
-
appraise "rails-
|
8
|
+
appraise "rails-5_0" do
|
9
|
+
gem "rails", "~> 5.0"
|
10
|
+
gem "rspec-rails"
|
11
|
+
gem "sqlite3", "~> 1.3.6"
|
12
|
+
gem "database_cleaner"
|
13
|
+
end
|
14
|
+
|
15
|
+
appraise "rails-5_1" do
|
16
|
+
gem "rails", "~> 5.1"
|
17
|
+
gem "rspec-rails"
|
18
|
+
gem "sqlite3", "~> 1.3.6"
|
19
|
+
gem "database_cleaner"
|
20
|
+
end
|
21
|
+
|
22
|
+
appraise "rails-5_2" do
|
9
23
|
gem "rails", "~> 5.2"
|
10
24
|
gem "rspec-rails"
|
11
25
|
gem "sqlite3", "~> 1.3.6"
|
12
26
|
gem "database_cleaner"
|
13
27
|
end
|
14
28
|
|
15
|
-
appraise "rails-
|
29
|
+
appraise "rails-5_0-graphiti-rails" do
|
30
|
+
gem "rails", "~> 5.0"
|
31
|
+
gem "rspec-rails"
|
32
|
+
gem "sqlite3", "~> 1.3.6"
|
33
|
+
gem "database_cleaner"
|
34
|
+
gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
|
35
|
+
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
36
|
+
end
|
37
|
+
|
38
|
+
appraise "rails-5_1-graphiti-rails" do
|
39
|
+
gem "rails", "~> 5.1"
|
40
|
+
gem "rspec-rails"
|
41
|
+
gem "sqlite3", "~> 1.3.6"
|
42
|
+
gem "database_cleaner"
|
43
|
+
gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
|
44
|
+
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
45
|
+
end
|
46
|
+
|
47
|
+
appraise "rails-5_2-graphiti-rails" do
|
16
48
|
gem "rails", "~> 5.2"
|
17
49
|
gem "rspec-rails"
|
18
50
|
gem "sqlite3", "~> 1.3.6"
|
@@ -22,14 +54,14 @@ appraise "rails-5-graphiti-rails" do
|
|
22
54
|
end
|
23
55
|
|
24
56
|
appraise "rails-6" do
|
25
|
-
gem "rails", "~> 6.0
|
57
|
+
gem "rails", "~> 6.0"
|
26
58
|
gem "rspec-rails"
|
27
59
|
gem "sqlite3", "~> 1.4.0"
|
28
60
|
gem "database_cleaner"
|
29
61
|
end
|
30
62
|
|
31
63
|
appraise "rails-6-graphiti-rails" do
|
32
|
-
gem "rails", "~> 6.0
|
64
|
+
gem "rails", "~> 6.0"
|
33
65
|
gem "rspec-rails"
|
34
66
|
gem "sqlite3", "~> 1.4.0"
|
35
67
|
gem "database_cleaner"
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
3
|
Features:
|
4
|
-
|
4
|
+
- [242](https://github.com/graphiti-api/graphiti/pull/242) Bump `jsonapi-renderer` to `~0.2.2` now that (https://github.com/jsonapi-rb/jsonapi-renderer/pull/36) is fixed.
|
5
5
|
- [158](https://github.com/graphiti-api/graphiti/pull/158) Filters options `allow_nil: true`
|
6
6
|
Option can be set at the resource level `Resource.filters_accept_nil_by_default = true`.
|
7
7
|
By default this is set to false. (@zeisler)
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
guard :rspec, cmd: "bundle exec rspec --color --format documentation" do
|
2
2
|
require "guard/rspec/dsl"
|
3
3
|
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
-
watch(%r{^spec/(.*)
|
4
|
+
watch(%r{^spec/(.*)/?(.*)_spec\.rb$})
|
5
5
|
|
6
6
|
# Feel free to open issues for suggestions and improvements
|
7
7
|
|
@@ -21,12 +21,12 @@ guard :rspec, cmd: "bundle exec rspec --color --format documentation" do
|
|
21
21
|
watch(rails.controllers) do |m|
|
22
22
|
[
|
23
23
|
rspec.spec.call("controllers/#{m[1]}_controller"),
|
24
|
-
rspec.spec.call("api/#{m[1]}")
|
24
|
+
rspec.spec.call("api/#{m[1]}")
|
25
25
|
]
|
26
26
|
end
|
27
27
|
|
28
28
|
# Rails config changes
|
29
|
-
watch(rails.spec_helper)
|
30
|
-
watch(rails.routes)
|
31
|
-
watch(rails.app_controller)
|
29
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
30
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
31
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
32
32
|
end
|
@@ -93,7 +93,7 @@ module Graphiti
|
|
93
93
|
raise "Unable to set #{self} default_attributes from #{attributes_class}. #{attributes_class} must be a kind of ApplicationRecord"
|
94
94
|
end
|
95
95
|
if attributes_class.table_exists?
|
96
|
-
|
96
|
+
attributes_class.columns.map do |c|
|
97
97
|
OpenStruct.new({name: c.name.to_sym, type: c.type})
|
98
98
|
end
|
99
99
|
else
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.0"
|
6
|
+
gem "rspec-rails"
|
7
|
+
gem "sqlite3", "~> 1.3.6"
|
8
|
+
gem "database_cleaner"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "pry"
|
12
|
+
gem "pry-byebug", platform: [:mri]
|
13
|
+
gem "appraisal"
|
14
|
+
gem "guard"
|
15
|
+
gem "guard-rspec"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.0"
|
6
|
+
gem "rspec-rails"
|
7
|
+
gem "sqlite3", "~> 1.3.6"
|
8
|
+
gem "database_cleaner"
|
9
|
+
gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
|
10
|
+
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem "pry"
|
14
|
+
gem "pry-byebug", platform: [:mri]
|
15
|
+
gem "appraisal"
|
16
|
+
gem "guard"
|
17
|
+
gem "guard-rspec"
|
18
|
+
end
|
19
|
+
|
20
|
+
gemspec path: "../"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.1"
|
6
|
+
gem "rspec-rails"
|
7
|
+
gem "sqlite3", "~> 1.3.6"
|
8
|
+
gem "database_cleaner"
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "pry"
|
12
|
+
gem "pry-byebug", platform: [:mri]
|
13
|
+
gem "appraisal"
|
14
|
+
gem "guard"
|
15
|
+
gem "guard-rspec"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec path: "../"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.1"
|
6
|
+
gem "rspec-rails"
|
7
|
+
gem "sqlite3", "~> 1.3.6"
|
8
|
+
gem "database_cleaner"
|
9
|
+
gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
|
10
|
+
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem "pry"
|
14
|
+
gem "pry-byebug", platform: [:mri]
|
15
|
+
gem "appraisal"
|
16
|
+
gem "guard"
|
17
|
+
gem "guard-rspec"
|
18
|
+
end
|
19
|
+
|
20
|
+
gemspec path: "../"
|
File without changes
|
File without changes
|
data/gemfiles/rails_6.gemfile
CHANGED
data/graphiti.gemspec
CHANGED
@@ -3,23 +3,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require "graphiti/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "graphiti"
|
7
|
+
spec.version = Graphiti::VERSION
|
8
|
+
spec.authors = ["Lee Richmond"]
|
9
|
+
spec.email = ["richmolj@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.homepage
|
13
|
-
spec.license
|
11
|
+
spec.summary = "Easily build jsonapi.org-compatible APIs"
|
12
|
+
spec.homepage = "https://github.com/graphiti-api/graphiti"
|
13
|
+
spec.license = "MIT"
|
14
14
|
|
15
|
-
spec.files
|
16
|
-
spec.bindir
|
17
|
-
spec.executables
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
spec.required_ruby_version = "~> 2.3"
|
20
20
|
|
21
21
|
spec.add_dependency "jsonapi-serializable", "~> 0.3.0"
|
22
|
-
spec.add_dependency "jsonapi-renderer", "0.2.
|
22
|
+
spec.add_dependency "jsonapi-renderer", "~> 0.2", ">= 0.2.2"
|
23
23
|
spec.add_dependency "dry-types", ">= 0.15.0", "< 2.0"
|
24
24
|
spec.add_dependency "graphiti_errors", "~> 1.1.0"
|
25
25
|
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
@@ -31,5 +31,4 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
32
|
spec.add_development_dependency "activemodel", ">= 4.1"
|
33
33
|
spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
|
34
|
-
spec.add_development_dependency "standard"
|
35
34
|
end
|
data/lib/graphiti.rb
CHANGED
@@ -13,7 +13,7 @@ require "graphiti_errors"
|
|
13
13
|
require "jsonapi/serializable"
|
14
14
|
|
15
15
|
module Graphiti
|
16
|
-
DEPRECATOR = ActiveSupport::Deprecation.new(
|
16
|
+
DEPRECATOR = ActiveSupport::Deprecation.new("2.0", "Graphiti")
|
17
17
|
|
18
18
|
# @api private
|
19
19
|
def self.context
|
@@ -33,9 +33,9 @@ module Graphiti
|
|
33
33
|
ensure
|
34
34
|
self.context = prior
|
35
35
|
|
36
|
-
resources.each
|
36
|
+
resources.each do |resource_class|
|
37
37
|
resource_class.sideloads.values.each(&:clear_resources)
|
38
|
-
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.config
|
@@ -17,7 +17,7 @@ module Graphiti
|
|
17
17
|
belongs_to: ::Graphiti::Sideload::BelongsTo,
|
18
18
|
has_one: ::Graphiti::Sideload::HasOne,
|
19
19
|
many_to_many: ::Graphiti::Sideload::ManyToMany,
|
20
|
-
polymorphic_belongs_to: ::Graphiti::Sideload::PolymorphicBelongsTo
|
20
|
+
polymorphic_belongs_to: ::Graphiti::Sideload::PolymorphicBelongsTo
|
21
21
|
}
|
22
22
|
end
|
23
23
|
|
@@ -33,7 +33,7 @@ module Graphiti
|
|
33
33
|
:suffix,
|
34
34
|
:not_suffix,
|
35
35
|
:match,
|
36
|
-
:not_match
|
36
|
+
:not_match
|
37
37
|
],
|
38
38
|
uuid: [:eq, :not_eq],
|
39
39
|
enum: [:eq, :not_eq],
|
@@ -45,7 +45,7 @@ module Graphiti
|
|
45
45
|
date: numerical_operators,
|
46
46
|
datetime: numerical_operators,
|
47
47
|
hash: [:eq],
|
48
|
-
array: [:eq]
|
48
|
+
array: [:eq]
|
49
49
|
}
|
50
50
|
end
|
51
51
|
|
@@ -12,7 +12,7 @@ module Graphiti
|
|
12
12
|
has_many: Graphiti::Adapters::ActiveRecord::HasManySideload,
|
13
13
|
has_one: Graphiti::Adapters::ActiveRecord::HasOneSideload,
|
14
14
|
belongs_to: Graphiti::Adapters::ActiveRecord::BelongsToSideload,
|
15
|
-
many_to_many: Graphiti::Adapters::ActiveRecord::ManyToManySideload
|
15
|
+
many_to_many: Graphiti::Adapters::ActiveRecord::ManyToManySideload
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
@@ -57,52 +57,61 @@ module Graphiti
|
|
57
57
|
filter_string_eql(scope, attribute, value, is_not: true)
|
58
58
|
end
|
59
59
|
|
60
|
-
def filter_string_prefix(scope, attribute, value, is_not: false)
|
61
|
-
column = column_for(scope, attribute)
|
62
|
-
map = value.map { |v| "#{v}%" }
|
63
|
-
clause = column.lower.matches_any(map)
|
64
|
-
is_not ? scope.where.not(clause) : scope.where(clause)
|
65
|
-
end
|
66
|
-
|
67
|
-
def filter_string_not_prefix(scope, attribute, value)
|
68
|
-
filter_string_prefix(scope, attribute, value, is_not: true)
|
69
|
-
end
|
70
|
-
|
71
|
-
def filter_string_suffix(scope, attribute, value, is_not: false)
|
72
|
-
column = column_for(scope, attribute)
|
73
|
-
map = value.map { |v| "%#{v}" }
|
74
|
-
clause = column.lower.matches_any(map)
|
75
|
-
is_not ? scope.where.not(clause) : scope.where(clause)
|
76
|
-
end
|
77
|
-
|
78
|
-
def filter_string_not_suffix(scope, attribute, value)
|
79
|
-
filter_string_suffix(scope, attribute, value, is_not: true)
|
80
|
-
end
|
81
|
-
|
82
60
|
# Arel has different match escaping behavior before rails 5.
|
83
61
|
# Since rails 4.x does not expose methods to escape LIKE statements
|
84
62
|
# anyway, we just don't support proper LIKE escaping in those versions.
|
85
|
-
if ::ActiveRecord.version >= Gem::Version.new(
|
63
|
+
if ::ActiveRecord.version >= Gem::Version.new("5.0.0")
|
86
64
|
def filter_string_match(scope, attribute, value, is_not: false)
|
87
|
-
|
88
|
-
column = column_for(scope, attribute)
|
89
|
-
map = value.map do |v|
|
90
|
-
v = v.downcase
|
91
|
-
v = scope.sanitize_sql_like(v)
|
65
|
+
clause = sanitized_like_for(scope, attribute, value) { |v|
|
92
66
|
"%#{v}%"
|
93
|
-
|
94
|
-
|
67
|
+
}
|
68
|
+
is_not ? scope.where.not(clause) : scope.where(clause)
|
69
|
+
end
|
70
|
+
|
71
|
+
def filter_string_prefix(scope, attribute, value, is_not: false)
|
72
|
+
clause = sanitized_like_for(scope, attribute, value) { |v|
|
73
|
+
"#{v}%"
|
74
|
+
}
|
75
|
+
is_not ? scope.where.not(clause) : scope.where(clause)
|
76
|
+
end
|
77
|
+
|
78
|
+
def filter_string_suffix(scope, attribute, value, is_not: false)
|
79
|
+
clause = sanitized_like_for(scope, attribute, value) { |v|
|
80
|
+
"%#{v}"
|
81
|
+
}
|
95
82
|
is_not ? scope.where.not(clause) : scope.where(clause)
|
96
83
|
end
|
97
84
|
else
|
98
85
|
def filter_string_match(scope, attribute, value, is_not: false)
|
99
86
|
column = column_for(scope, attribute)
|
100
|
-
map = value.map
|
87
|
+
map = value.map { |v|
|
101
88
|
"%#{v.downcase}%"
|
102
|
-
|
89
|
+
}
|
90
|
+
clause = column.lower.matches_any(map)
|
91
|
+
is_not ? scope.where.not(clause) : scope.where(clause)
|
92
|
+
end
|
93
|
+
|
94
|
+
def filter_string_prefix(scope, attribute, value, is_not: false)
|
95
|
+
column = column_for(scope, attribute)
|
96
|
+
map = value.map { |v| "#{v}%" }
|
103
97
|
clause = column.lower.matches_any(map)
|
104
98
|
is_not ? scope.where.not(clause) : scope.where(clause)
|
105
99
|
end
|
100
|
+
|
101
|
+
def filter_string_suffix(scope, attribute, value, is_not: false)
|
102
|
+
column = column_for(scope, attribute)
|
103
|
+
map = value.map { |v| "%#{v}" }
|
104
|
+
clause = column.lower.matches_any(map)
|
105
|
+
is_not ? scope.where.not(clause) : scope.where(clause)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def filter_string_not_prefix(scope, attribute, value)
|
110
|
+
filter_string_prefix(scope, attribute, value, is_not: true)
|
111
|
+
end
|
112
|
+
|
113
|
+
def filter_string_not_suffix(scope, attribute, value)
|
114
|
+
filter_string_suffix(scope, attribute, value, is_not: true)
|
106
115
|
end
|
107
116
|
|
108
117
|
def filter_string_not_match(scope, attribute, value)
|
@@ -150,7 +159,7 @@ module Graphiti
|
|
150
159
|
|
151
160
|
# Ensure fractional seconds don't matter
|
152
161
|
def filter_datetime_eq(scope, attribute, value, is_not: false)
|
153
|
-
ranges = value.map { |v| (v..v + 1.second - 0.00000001) }
|
162
|
+
ranges = value.map { |v| (v..v + 1.second - 0.00000001) unless v.nil? }
|
154
163
|
clause = {attribute => ranges}
|
155
164
|
is_not ? scope.where.not(clause) : scope.where(clause)
|
156
165
|
end
|
@@ -273,8 +282,8 @@ module Graphiti
|
|
273
282
|
|
274
283
|
# (see Adapters::Abstract#update)
|
275
284
|
def update(model_class, update_params)
|
276
|
-
instance = model_class.find(update_params.
|
277
|
-
instance.update_attributes(update_params)
|
285
|
+
instance = model_class.find(update_params.only(:id))
|
286
|
+
instance.update_attributes(update_params.except(:id))
|
278
287
|
instance
|
279
288
|
end
|
280
289
|
|
@@ -298,6 +307,26 @@ module Graphiti
|
|
298
307
|
table[name]
|
299
308
|
end
|
300
309
|
end
|
310
|
+
|
311
|
+
def sanitized_like_for(scope, attribute, value, &block)
|
312
|
+
escape_char = '\\'
|
313
|
+
column = column_for(scope, attribute)
|
314
|
+
map = value.map { |v|
|
315
|
+
v = v.downcase
|
316
|
+
v = Sanitizer.sanitize_like(v, escape_char)
|
317
|
+
block.call v
|
318
|
+
}
|
319
|
+
|
320
|
+
column.lower.matches_any(map, escape_char, true)
|
321
|
+
end
|
322
|
+
|
323
|
+
class Sanitizer
|
324
|
+
extend ::ActiveRecord::Sanitization::ClassMethods
|
325
|
+
|
326
|
+
def self.sanitize_like(*args)
|
327
|
+
sanitize_sql_like(*args)
|
328
|
+
end
|
329
|
+
end
|
301
330
|
end
|
302
331
|
end
|
303
332
|
end
|