activerecord-extensions 0.1.3 → 0.1.4
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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d36bf59767f34bdcd21148b131903cbb50e70c26
|
4
|
+
data.tar.gz: ad9529b8bbaac94135d82ee71e9fdaad0c76b248
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36d4fba386b609c8577a27a4a7965623cdb2d7eb9eea7a2a6d2fb91d2791bc081bbdf3efaf4253d22cefb1b7a183a085d5032561d70507a10ab0b649bf5dd2ee
|
7
|
+
data.tar.gz: c792ed26f252ce17d3948ac7d48094782e26d01093bc18b6c4bd6d82412837d123cfb13cb3cc276373a0db83fc1f7f84fe37ee9abd9766d322e60be18febc7f5
|
@@ -1,8 +1,13 @@
|
|
1
1
|
ActiveRecord::QueryMethods.module_eval do
|
2
2
|
def bind_parameters(opts)
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
binds = []
|
4
|
+
opts.each do |(column, value)|
|
5
|
+
if(value.nil?)
|
6
|
+
raise ArgumentError.new("nils are not allowed in bind parameter. please sanitize value for column: '#{column}'")
|
7
|
+
end
|
8
|
+
binds.push [@klass.columns_hash[column.to_s], value]
|
9
|
+
end
|
10
|
+
self.bind_values += binds
|
6
11
|
self
|
7
12
|
end
|
8
13
|
end
|
@@ -2,15 +2,21 @@ module ActiverecordExtensions
|
|
2
2
|
module QueryBuilder
|
3
3
|
|
4
4
|
def where_gt(attribute, value)
|
5
|
-
where_with_bind(arel_table[attribute].gt(Arel::Nodes::BindParam.new), attribute
|
5
|
+
where_with_bind(arel_table[attribute].gt(Arel::Nodes::BindParam.new), {attribute => value})
|
6
6
|
end
|
7
7
|
|
8
8
|
def where_lt(attribute, value)
|
9
|
-
where_with_bind(arel_table[attribute].lt(Arel::Nodes::BindParam.new), attribute
|
9
|
+
where_with_bind(arel_table[attribute].lt(Arel::Nodes::BindParam.new), {attribute => value})
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def where_in(attribute, values)
|
13
|
+
bind_params = values.map{ Arel::Nodes::BindParam.new }
|
14
|
+
column_values = values.each_with_object([]) { |value, column_values| column_values.push [attribute, value] }
|
15
|
+
where_with_bind(arel_table[attribute].in(bind_params), column_values)
|
16
|
+
end
|
17
|
+
|
18
|
+
def where_with_bind(clause, opt)
|
19
|
+
where(clause).bind_parameters(opt)
|
14
20
|
end
|
15
21
|
|
16
22
|
end
|