active_record_extended 0.4.0 → 0.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -0
  3. data/.gitignore +0 -0
  4. data/.rspec +0 -0
  5. data/.rubocop.yml +0 -0
  6. data/.ruby-gemset +0 -0
  7. data/.ruby-version +0 -0
  8. data/.travis.yml +1 -0
  9. data/CHANGELOG.md +11 -0
  10. data/CODE_OF_CONDUCT.md +0 -0
  11. data/Gemfile +0 -0
  12. data/Gemfile.lock +3 -3
  13. data/LICENSE.txt +0 -0
  14. data/README.md +0 -0
  15. data/Rakefile +0 -0
  16. data/active_record_extended.gemspec +1 -1
  17. data/gemfiles/activerecord-50.gemfile +8 -0
  18. data/gemfiles/activerecord-51.gemfile +0 -0
  19. data/gemfiles/activerecord-52+.gemfile +0 -0
  20. data/gemfiles/activerecord-52.gemfile +0 -0
  21. data/lib/active_record_extended/active_record.rb +4 -1
  22. data/lib/active_record_extended/arel/nodes.rb +0 -0
  23. data/lib/active_record_extended/arel/predications.rb +0 -0
  24. data/lib/active_record_extended/arel/visitors/postgresql_decorator.rb +0 -0
  25. data/lib/active_record_extended/arel.rb +0 -0
  26. data/lib/active_record_extended/patch/5_0/predicate_builder_decorator.rb +87 -0
  27. data/lib/active_record_extended/patch/5_1/where_clause.rb +0 -0
  28. data/lib/active_record_extended/patch/5_2/where_clause.rb +0 -0
  29. data/lib/active_record_extended/predicate_builder/array_handler_decorator.rb +0 -0
  30. data/lib/active_record_extended/query_methods/any_of.rb +0 -0
  31. data/lib/active_record_extended/query_methods/either.rb +0 -0
  32. data/lib/active_record_extended/query_methods/where_chain.rb +0 -0
  33. data/lib/active_record_extended/version.rb +1 -1
  34. data/lib/active_record_extended.rb +0 -0
  35. data/spec/active_record_extended_spec.rb +0 -0
  36. data/spec/query_methods/any_of_spec.rb +0 -0
  37. data/spec/query_methods/array_query_spec.rb +0 -0
  38. data/spec/query_methods/either_spec.rb +0 -0
  39. data/spec/query_methods/hash_query_spec.rb +0 -0
  40. data/spec/spec_helper.rb +0 -0
  41. data/spec/sql_inspections/any_of_sql_spec.rb +0 -0
  42. data/spec/sql_inspections/arel/array_spec.rb +0 -0
  43. data/spec/sql_inspections/contains_sql_queries_spec.rb +0 -0
  44. data/spec/sql_inspections/either_sql_spec.rb +0 -0
  45. data/spec/support/database_cleaner.rb +0 -0
  46. data/spec/support/models.rb +0 -0
  47. metadata +8 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3676a5b5f744f28f9e545a951e006f03457660046d5908d5f5fdc4200591c6c6
4
- data.tar.gz: '0434468d2a6f1988df93a4150b7276e1d0d0538252519cf715e76cd12ba5e8de'
3
+ metadata.gz: 56c4be1e6e48ce5c2c7430545666c5a972d8355539d9f4eacd606bfb8919eb2c
4
+ data.tar.gz: d4ceaaaa423fc093cec3fb463ec2e2a54f9eba2f7f8b13ca0f2c55b45b4b38d1
5
5
  SHA512:
6
- metadata.gz: 0bafb6e58693b523541fe90556bf863a271d93310e76de4929214f4b6e06117da92aa625dad7c932f1a5f58b8647b8b3f521de48b8428d011402b1c329af0fb4
7
- data.tar.gz: 234e63478d2f25f2eccdc5fe5c6a96a7a500ae0f5207a8232fdef30638cfb7e773cec4a413cc8073419525c26729796a7766288c955500f402a88e4720728523
6
+ metadata.gz: 1d5132209987cef0e73351c8343121998a107fad83d29d0e4b9f44fff72254b8c3f97f8b3ac237eb54f6aeb2b53254f5d93c4b63a0bc3597084e848795be9ce2
7
+ data.tar.gz: a9f707ddb4b0734e9fa8e62403e8787859e464e2b0d288dc6b51ab15abf235e1420398cbe7292de7987b42463572c96028f28dcd84cde16658df67a809ef65f5
data/.codeclimate.yml CHANGED
File without changes
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.rubocop.yml CHANGED
File without changes
data/.ruby-gemset CHANGED
File without changes
data/.ruby-version CHANGED
File without changes
data/.travis.yml CHANGED
@@ -12,6 +12,7 @@ branches:
12
12
  only:
13
13
  - master
14
14
  gemfile:
15
+ - gemfiles/activerecord-50.gemfile
15
16
  - gemfiles/activerecord-51.gemfile
16
17
  - gemfiles/activerecord-52.gemfile
17
18
  - gemfiles/activerecord-52+.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.5.0.beta1 - May 26th 2018
2
+
3
+ Added support for Rails 5.0.x
4
+
5
+ ### Warning for Rails 5.0.x Projects
6
+ The proposed changes to this could cause unintended behavior in existing Rails 5.0.x applications.
7
+ This is due to the overwrite needed to be done on its internal Predicate builder.
8
+ Rails projects above 5.0.x should not experience any unforeseen issues since they contain the necessary structure required.
9
+
10
+ **Use with caution.** And always make sure you have good tests to verify everything in your application.
11
+
1
12
  # 0.4.0 - May 9th 2018
2
13
 
3
14
  - Use Arel's `or` for grouping queries when using `#any_of` or `#none_of`
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_record_extended (0.4.0)
5
- activerecord (>= 5.1, < 6.0)
4
+ active_record_extended (0.5.0.beta1)
5
+ activerecord (>= 5.0, < 6.0)
6
6
  ar_outer_joins (~> 0.2)
7
7
  pg (~> 0.18)
8
8
 
@@ -60,7 +60,7 @@ GEM
60
60
  diff-lcs (>= 1.2.0, < 2.0)
61
61
  rspec-support (~> 3.7.0)
62
62
  rspec-support (3.7.1)
63
- rubocop (0.55.0)
63
+ rubocop (0.56.0)
64
64
  parallel (~> 1.10)
65
65
  parser (>= 2.5)
66
66
  powerpack (~> 0.1)
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "activerecord", ">= 5.1", "< 6.0"
24
+ spec.add_dependency "activerecord", ">= 5.0", "< 6.0"
25
25
  spec.add_dependency "ar_outer_joins", "~> 0.2"
26
26
  spec.add_dependency "pg", "~> 0.18"
27
27
 
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: ".."
6
+
7
+ gem "activerecord", "~> 5.0.0"
8
+ gem "pg", "~> 0.18"
File without changes
File without changes
File without changes
@@ -7,7 +7,10 @@ require "active_record/relation/query_methods"
7
7
  require "active_record_extended/predicate_builder/array_handler_decorator"
8
8
  Dir["#{File.dirname(__FILE__)}/query_methods/**/*.rb"].each { |f| require File.expand_path(f) }
9
9
 
10
- if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 1
10
+ if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR <= 1
11
+ if ActiveRecord::VERSION::MINOR.zero?
12
+ require "active_record_extended/patch/5_0/predicate_builder_decorator"
13
+ end
11
14
  require "active_record_extended/patch/5_1/where_clause"
12
15
  elsif ActiveRecord::VERSION::MAJOR >= 5
13
16
  require "active_record_extended/patch/5_2/where_clause"
File without changes
File without changes
File without changes
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Stripped from Rails 5.1.x
4
+ # This patch is used so that when querying with hash elements that do not belong to an association,
5
+ # but instead a data attribute. It returns the corrected attribute binds back to the query builder.
6
+ #
7
+ # Without joins
8
+ # Before:
9
+ # Person.where.contains(data: { nickname: "george" })
10
+ # #=> "SELECT \"people\".* FROM \"people\" WHERE (\"data\".\"nickname\" @> 'george')"
11
+ #
12
+ # After:
13
+ # Person.where.contains(data: { nickname: "george" })
14
+ # #=> "SELECT \"people\".* FROM \"people\" WHERE (\"people\".\"data\" @> '\"nickname\"=>\"george\"')"
15
+ #
16
+ # With Joins
17
+ # Before:
18
+ # Tag.joins(:person).where.contains(people: { data: { nickname: "george" } })
19
+ # #=> NoMethodError: undefined method `type' for nil:NilClass
20
+ #
21
+ # After:
22
+ # Tag.joins(:person).where.contains(people: { data: { nickname: "george" } })
23
+ # #=> "SELECT \"tags\".* FROM \"tags\" INNER JOIN \"people\" ON \"people\".\"id\" = \"tags\".\"person_id\"
24
+ # WHERE (\"people\".\"data\" @> '\"nickname\"=>\"george\"')"
25
+ #
26
+ module ActiveRecord
27
+ class TableMetadata
28
+ def has_column?(column_name) # rubocop:disable Naming/PredicateName
29
+ klass&.columns_hash&.key?(column_name.to_s)
30
+ end
31
+ end
32
+
33
+ class PredicateBuilder
34
+ def create_binds_for_hash(attributes) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
35
+ result = attributes.dup
36
+ binds = []
37
+
38
+ attributes.each do |column_name, value| # rubocop:disable Metrics/BlockLength
39
+ if value.is_a?(Hash) && !table.has_column?(column_name)
40
+ attrs, bvs = associated_predicate_builder(column_name).create_binds_for_hash(value)
41
+ result[column_name] = attrs
42
+ binds += bvs
43
+ next
44
+ elsif value.is_a?(Relation)
45
+ binds += value.bound_attributes
46
+ elsif value.is_a?(Range) && !table.type(column_name).respond_to?(:subtype)
47
+ first = value.begin
48
+ last = value.end
49
+ unless first.respond_to?(:infinite?) && first.infinite?
50
+ binds << build_bind_param(column_name, first)
51
+ first = Arel::Nodes::BindParam.new
52
+ end
53
+ unless last.respond_to?(:infinite?) && last.infinite?
54
+ binds << build_bind_param(column_name, last)
55
+ last = Arel::Nodes::BindParam.new
56
+ end
57
+
58
+ result[column_name] = RangeHandler::RangeWithBinds.new(first, last, value.exclude_end?)
59
+ elsif can_be_bound?(column_name, value)
60
+ result[column_name] = Arel::Nodes::BindParam.new
61
+ binds << build_bind_param(column_name, value)
62
+ end
63
+
64
+ # Find the foreign key when using queries such as:
65
+ # Post.where(author: author)
66
+ #
67
+ # For polymorphic relationships, find the foreign key and type:
68
+ # PriceEstimate.where(estimate_of: treasure)
69
+ if table.associated_with?(column_name)
70
+ result[column_name] = AssociationQueryHandler.value_for(table, column_name, value)
71
+ end
72
+ end
73
+
74
+ [result, binds]
75
+ end
76
+
77
+ def can_be_bound?(column_name, value)
78
+ return if table.associated_with?(column_name)
79
+ case value
80
+ when Array, Range
81
+ table.type(column_name).respond_to?(:subtype)
82
+ else
83
+ !value.nil? && handler_for(value).is_a?(BasicObjectHandler)
84
+ end
85
+ end
86
+ end
87
+ end
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordExtended
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0.beta1"
5
5
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Protacio-Karaszi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-05-09 00:00:00.000000000 Z
13
+ date: 2018-05-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5.1'
21
+ version: '5.0'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '6.0'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '5.1'
31
+ version: '5.0'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '6.0'
@@ -144,6 +144,7 @@ files:
144
144
  - active_record_extended.gemspec
145
145
  - bin/console
146
146
  - bin/setup
147
+ - gemfiles/activerecord-50.gemfile
147
148
  - gemfiles/activerecord-51.gemfile
148
149
  - gemfiles/activerecord-52+.gemfile
149
150
  - gemfiles/activerecord-52.gemfile
@@ -153,6 +154,7 @@ files:
153
154
  - lib/active_record_extended/arel/nodes.rb
154
155
  - lib/active_record_extended/arel/predications.rb
155
156
  - lib/active_record_extended/arel/visitors/postgresql_decorator.rb
157
+ - lib/active_record_extended/patch/5_0/predicate_builder_decorator.rb
156
158
  - lib/active_record_extended/patch/5_1/where_clause.rb
157
159
  - lib/active_record_extended/patch/5_2/where_clause.rb
158
160
  - lib/active_record_extended/predicate_builder/array_handler_decorator.rb
@@ -187,9 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
189
  version: '0'
188
190
  required_rubygems_version: !ruby/object:Gem::Requirement
189
191
  requirements:
190
- - - ">="
192
+ - - ">"
191
193
  - !ruby/object:Gem::Version
192
- version: '0'
194
+ version: 1.3.1
193
195
  requirements: []
194
196
  rubyforge_project:
195
197
  rubygems_version: 2.7.6