custom_query_methods 0.1.6 → 0.1.8
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 +4 -4
- data/custom_query_methods-0.1.6.gem +0 -0
- data/custom_query_methods-0.1.7.gem +0 -0
- data/lib/custom_query_methods/active_record.rb +20 -0
- data/lib/custom_query_methods/railtie.rb +4 -4
- data/lib/custom_query_methods/version.rb +1 -1
- data/lib/custom_query_methods/where_clause_factory.rb +32 -0
- data/lib/custom_query_methods.rb +1 -1
- metadata +5 -2
- data/lib/custom_query_methods/active_record_extension.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0923b7835bffac6b76fba0a176bb27abd37dbb64746adecd0f06931ec9d45f51'
|
4
|
+
data.tar.gz: 16683928fd340002ce0589ffd0e3c3b71d04ea799e865a81555c7b6e3322c60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b5ebcb4d32dc2f4569a899773e450e32550684c4cb4aadd0f282ec0dfc441bcefedc012f9b8b32c86ebee72fd09924bf284a24f944a4d81224149cc9e799ca9
|
7
|
+
data.tar.gz: 844aa02bc177e83c190dfda54c13118e1e343adfe9205751e394cdf16cc7a98c4852a145934cdd615219eff2d8d3eca0d79bb8a53a3a4c0433ab07bb01399233
|
Binary file
|
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CustomQueryMethods
|
2
|
+
module ActiveRecord
|
3
|
+
def where_bind(opts = :chain, *rest)
|
4
|
+
if :chain == opts
|
5
|
+
::ActiveRecord::QueryMethods::WhereChain.new(spawn)
|
6
|
+
elsif opts.blank?
|
7
|
+
self
|
8
|
+
else
|
9
|
+
spawn.where_bind!(opts, *rest)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def where_bind!(opts, *rest) # :nodoc:
|
14
|
+
opts = sanitize_forbidden_attributes(opts)
|
15
|
+
references!(::ActiveRecord::PredicateBuilder.references(opts)) if Hash === opts
|
16
|
+
self.where_clause += where_clause_factory.build(opts, rest)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'active_record'
|
2
2
|
|
3
3
|
module CustomQueryMethods
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
-
initializer 'custom_query_methods
|
6
|
-
ActiveSupport.on_load
|
7
|
-
ActiveRecord::
|
5
|
+
initializer 'custom_query_methods' do
|
6
|
+
ActiveSupport.on_load(:active_record) do
|
7
|
+
::ActiveRecord::Relation.include CustomQueryMethods::ActiveRecord
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomQueryMethods
|
4
|
+
class WhereClauseFactory # :nodoc:
|
5
|
+
def initialize(klass, predicate_builder)
|
6
|
+
@klass = klass
|
7
|
+
@predicate_builder = predicate_builder
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(opts, other)
|
11
|
+
case opts
|
12
|
+
when String, Array
|
13
|
+
parts = [klass.sanitize_sql(other.empty? ? opts : ([opts] + other))]
|
14
|
+
when Hash
|
15
|
+
attributes = predicate_builder.resolve_column_aliases(opts)
|
16
|
+
attributes.stringify_keys!
|
17
|
+
|
18
|
+
parts = predicate_builder.build_from_hash(attributes)
|
19
|
+
when Arel::Nodes::Node
|
20
|
+
parts = [opts]
|
21
|
+
else
|
22
|
+
raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
|
23
|
+
end
|
24
|
+
|
25
|
+
WhereClause.new(parts)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
attr_reader :klass, :predicate_builder
|
31
|
+
end
|
32
|
+
end
|
data/lib/custom_query_methods.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_query_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tsotne
|
@@ -59,11 +59,14 @@ files:
|
|
59
59
|
- custom_query_methods-0.1.3.gem
|
60
60
|
- custom_query_methods-0.1.4.gem
|
61
61
|
- custom_query_methods-0.1.5.gem
|
62
|
+
- custom_query_methods-0.1.6.gem
|
63
|
+
- custom_query_methods-0.1.7.gem
|
62
64
|
- custom_query_methods.gemspec
|
63
65
|
- lib/custom_query_methods.rb
|
64
|
-
- lib/custom_query_methods/
|
66
|
+
- lib/custom_query_methods/active_record.rb
|
65
67
|
- lib/custom_query_methods/railtie.rb
|
66
68
|
- lib/custom_query_methods/version.rb
|
69
|
+
- lib/custom_query_methods/where_clause_factory.rb
|
67
70
|
homepage: http://example.com
|
68
71
|
licenses:
|
69
72
|
- MIT
|