ransack 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,16 +53,8 @@ module Ransack
53
53
  end
54
54
 
55
55
  def type_for(attr)
56
- return nil unless attr
57
- name = attr.name.to_s
58
- table = attr.relation.name
59
-
60
- unless @engine.connection.table_exists?(table)
61
- raise "No table named #{table} exists"
62
- end
63
-
64
- # TODO: optimize
65
- @engine.connection.columns(table).detect {|c| c.name == name}.type
56
+ return nil unless attr && attr.valid?
57
+ klassify(attr.parent).columns_hash[attr.arel_attribute.name.to_s].type
66
58
  end
67
59
 
68
60
  private
@@ -51,9 +51,9 @@ module Ransack
51
51
  end
52
52
 
53
53
  def type_for(attr)
54
- return nil unless attr
55
- name = attr.name.to_s
56
- table = attr.relation.table_name
54
+ return nil unless attr && attr.valid?
55
+ name = attr.arel_attribute.name.to_s
56
+ table = attr.arel_attribute.relation.table_name
57
57
 
58
58
  unless @engine.connection_pool.table_exists?(table)
59
59
  raise "No table named #{table} exists"
@@ -26,7 +26,7 @@ module Ransack
26
26
  if ransacker
27
27
  return ransacker.type
28
28
  else
29
- context.type_for(attr)
29
+ context.type_for(self)
30
30
  end
31
31
  end
32
32
 
@@ -7,6 +7,7 @@ module Ransack
7
7
  def attr
8
8
  @attr ||= ransacker ? ransacker.attr_from(self) : context.table_for(parent)[attr_name]
9
9
  end
10
+ alias :arel_attribute :attr
10
11
 
11
12
  def ransacker
12
13
  klass._ransackers[attr_name]
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ernie Miller