activerecord-extensions 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 44c25bfe7af107d8f5983426160690204ccdc4dc
4
- data.tar.gz: cd4af3a9edaa9bf394e46d702dbe8cc1f7e03487
3
+ metadata.gz: d36bf59767f34bdcd21148b131903cbb50e70c26
4
+ data.tar.gz: ad9529b8bbaac94135d82ee71e9fdaad0c76b248
5
5
  SHA512:
6
- metadata.gz: 7fe71a47050ccee63c1ff7b93665d9068e1ee39c72c2bedc8a6b74e68a07dd2f32318930ac70cf7feab1bc33c96f65205115e1d6d6decc9ad424eb504d15764e
7
- data.tar.gz: d141144d511cecaf9df50aba598d4b9686d581d5672ec5fd2d42520521cb39832b85d9be7b12edf8223a749e9d9101575445e6f9cfafc70ac454abe43b71f4c5
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
- opts = ActiveRecord::PredicateBuilder.resolve_column_aliases(klass, opts)
4
- _, bind_values = create_binds(opts)
5
- self.bind_values += bind_values
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, value)
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, value)
9
+ where_with_bind(arel_table[attribute].lt(Arel::Nodes::BindParam.new), {attribute => value})
10
10
  end
11
11
 
12
- def where_with_bind(clause, attribute, value)
13
- where(clause).bind_parameters({attribute => value})
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
@@ -1,3 +1,3 @@
1
1
  module ActiverecordExtensions
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faisal Mansoor