ransack_ui 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ module RansackUI
2
+ module Adapters
3
+ module ActiveRecord
4
+ module Base
5
+
6
+ def self.extended(base)
7
+ base.class_eval do
8
+ class_attribute :_ransackable_associations
9
+ class_attribute :_ransack_can_autocomplete
10
+ self._ransackable_associations ||= []
11
+ self._ransack_can_autocomplete = false
12
+ end
13
+ end
14
+
15
+ def has_ransackable_associations(associations)
16
+ self._ransackable_associations = associations
17
+ end
18
+
19
+ def ransack_can_autocomplete
20
+ self._ransack_can_autocomplete = true
21
+ end
22
+
23
+ # Return array of attributes with [name, type]
24
+ # (Default to :string type for ransackers)
25
+ def ransackable_attributes(auth_object = nil)
26
+ columns.map{|c| [c.name, c.type] } +
27
+ _ransackers.keys.map {|k| [k, :string] }
28
+ end
29
+
30
+ def ransackable_associations(auth_object = nil)
31
+ all_associations = reflect_on_all_associations.map {|a| a.name.to_s}
32
+ if self._ransackable_associations.any?
33
+ # Return intersection of all associations, and associations defined on the model
34
+ all_associations & self._ransackable_associations
35
+ else
36
+ all_associations
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # Extend original ransack adapter first
2
+ require 'ransack/adapters/active_record'
3
+
4
+ require 'ransack_ui/adapters/active_record/base'
5
+ ActiveRecord::Base.extend RansackUI::Adapters::ActiveRecord::Base
@@ -1,3 +1,3 @@
1
1
  module RansackUI
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/ransack_ui.rb CHANGED
@@ -4,4 +4,5 @@ require "core_ext/enumerable"
4
4
  require "chronic"
5
5
 
6
6
  # Require ransack overrides
7
+ require 'ransack_ui/adapters/active_record'
7
8
  Dir.glob(File.expand_path('../ransack_ui/ransack_overrides/**/*.rb', __FILE__)) {|f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -51,6 +51,8 @@ files:
51
51
  - config/locales/en.yml
52
52
  - lib/core_ext/enumerable.rb
53
53
  - lib/ransack_ui.rb
54
+ - lib/ransack_ui/adapters/active_record.rb
55
+ - lib/ransack_ui/adapters/active_record/base.rb
54
56
  - lib/ransack_ui/controller_helpers.rb
55
57
  - lib/ransack_ui/rails/engine.rb
56
58
  - lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb
@@ -76,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
78
  version: '0'
77
79
  segments:
78
80
  - 0
79
- hash: -2183248768965735638
81
+ hash: 4121058446374876496
80
82
  required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  none: false
82
84
  requirements:
@@ -85,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  segments:
87
89
  - 0
88
- hash: -2183248768965735638
90
+ hash: 4121058446374876496
89
91
  requirements: []
90
92
  rubyforge_project:
91
93
  rubygems_version: 1.8.24