rails-tables 0.4.2 → 0.4.3

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.
data/README.md CHANGED
@@ -12,7 +12,7 @@ A clean jQuery datatables DSL
12
12
  [jqd-railscast]: http://railscasts.com/episodes/340-datatables (Episode #340: Datatables)
13
13
  [squeel]: https://github.com/ernie/squeel (Squeel: ActiveRecord 3, improved)
14
14
 
15
- Version: 0.4.2
15
+ Version: 0.4.3
16
16
 
17
17
  Please refer to the [RailsTables Wiki][wiki] for:
18
18
 
data/app/tables/column.rb CHANGED
@@ -3,10 +3,10 @@ class Column
3
3
  attr_accessor :model, :name, :method, :column_source, :render_with, :sortable, :searchable, :blank_value
4
4
  def initialize(model, name, *args)
5
5
  self.model = model
6
- self.name = name
6
+ self.name = name.to_s
7
7
 
8
8
  attributes = args.pop || {}
9
- self.method = attributes.fetch(:method, name)
9
+ self.method = attributes.fetch(:method, name).to_s
10
10
  self.column_source = attributes.fetch(:column_source, '').to_s
11
11
  self.render_with = attributes.fetch(:render_with, :default_render)
12
12
  self.sortable = attributes.fetch(:sortable, true)
@@ -71,9 +71,19 @@ attr_accessor :joins
71
71
  def joins
72
72
  @joins ||= (self.columns.map(&:column_source).reject(&:blank?) + self.class.joins).uniq
73
73
  end
74
+
75
+ class_attribute :searches
76
+ self.searches = []
77
+ def self.search_on(column_source, methods)
78
+ Array(methods).each do |method|
79
+ join column_source
80
+ self.searches += [{column_source: column_source.to_s, method: method.to_s}]
81
+ end
82
+ end
74
83
  attr_accessor :searches
75
84
  def searches
76
- @searches ||= self.columns.select(&:searchable).select{|c| c.column_source.present?}
85
+ @searches ||= (
86
+ self.columns.select(&:searchable).select{|c| c.column_source.present?}.map{|c| {column_source: c.column_source, method: c.method} } + self.class.searches).uniq
77
87
  end
78
88
 
79
89
  private
@@ -109,9 +119,9 @@ private
109
119
 
110
120
  def search(terms)
111
121
  terms = terms.split if terms.is_a? String
112
- self.searches.map do |column|
122
+ self.searches.map do |search|
113
123
  terms.map do |word|
114
- Squeel::Nodes::KeyPath.new(column.column_source.split('.') << Squeel::Nodes::Stub.new(column.method)) =~ "%#{word}%"
124
+ Squeel::Nodes::KeyPath.new(search[:column_source].split('.') << Squeel::Nodes::Stub.new(search[:method])) =~ "%#{word}%"
115
125
  end.compact.inject(&:|)
116
126
  end.compact.inject(&:|)
117
127
  end
@@ -1,3 +1,3 @@
1
1
  module RailsTables
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: