Class: MagicGrid::Column
- Inherits:
-
Object
- Object
- MagicGrid::Column
- Defined in:
- lib/magic_grid/column.rb
Direct Known Subclasses
Class Method Summary collapse
- .columns_for_collection(collection, columns, searchables) ⇒ Object
- .hash_string(column_or_columns) ⇒ Object
- .searchable_column(searchable, columns, collection) ⇒ Object
Instance Method Summary collapse
- #custom_sql ⇒ Object
- #html_classes ⇒ Object
- #id ⇒ Object
- #label ⇒ Object
- #name ⇒ Object
- #reader ⇒ Object
- #sortable? ⇒ Boolean
Class Method Details
.columns_for_collection(collection, columns, searchables) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/magic_grid/column.rb', line 4 def self.columns_for_collection(collection, columns, searchables) columns.each_with_index.map { |c, i| MagicGrid::Column.new(collection, c, i) }.tap do |cols| if searchables == false searchables = [] else searchables = Array(searchables).map { |s| searchable_column(s, cols, collection) } end collection.searchable_columns = searchables.compact end end |
.hash_string(column_or_columns) ⇒ Object
34 35 36 |
# File 'lib/magic_grid/column.rb', line 34 def self.hash_string(column_or_columns) Array(column_or_columns).map(&:label).join.hash.abs.to_s(36) end |
.searchable_column(searchable, columns, collection) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/magic_grid/column.rb', line 19 def self.searchable_column(searchable, columns, collection) case searchable when Symbol columns.find {|col| col.name == searchable} || FilterOnlyColumn.new(searchable, collection) when Integer columns[searchable] when String FilterOnlyColumn.new(searchable) when true nil else raise "Searchable must be identifiable: #{searchable}" end end |
Instance Method Details
#custom_sql ⇒ Object
46 47 48 |
# File 'lib/magic_grid/column.rb', line 46 def custom_sql @col[:sql] end |
#html_classes ⇒ Object
58 59 60 |
# File 'lib/magic_grid/column.rb', line 58 def html_classes Array(@col[:class]).join ' ' end |
#id ⇒ Object
50 51 52 |
# File 'lib/magic_grid/column.rb', line 50 def id @col[:id] end |
#label ⇒ Object
38 39 40 |
# File 'lib/magic_grid/column.rb', line 38 def label @col[:label] end |
#name ⇒ Object
54 55 56 |
# File 'lib/magic_grid/column.rb', line 54 def name @col[:col] end |
#reader ⇒ Object
62 63 64 |
# File 'lib/magic_grid/column.rb', line 62 def reader @col[:to_s] || @col[:col] end |
#sortable? ⇒ Boolean
42 43 44 |
# File 'lib/magic_grid/column.rb', line 42 def sortable? not custom_sql.blank? end |