Class: MagicGrid::Column
- Inherits:
-
Object
- Object
- MagicGrid::Column
- Defined in:
- lib/magic_grid/column.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#order ⇒ Object
Returns the value of attribute order.
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
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'lib/magic_grid/column.rb', line 5 def order @order end |
Class Method Details
.columns_for_collection(collection, columns, searchables) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/magic_grid/column.rb', line 7 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
37 38 39 |
# File 'lib/magic_grid/column.rb', line 37 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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/magic_grid/column.rb', line 22 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
49 50 51 |
# File 'lib/magic_grid/column.rb', line 49 def custom_sql @col[:sql] end |
#html_classes ⇒ Object
61 62 63 64 |
# File 'lib/magic_grid/column.rb', line 61 def html_classes @html_classes ||= (Array(@col[:class]) << order.css_class) @html_classes.join(' ') end |
#id ⇒ Object
53 54 55 |
# File 'lib/magic_grid/column.rb', line 53 def id @col[:id] end |
#label ⇒ Object
41 42 43 |
# File 'lib/magic_grid/column.rb', line 41 def label @col[:label] end |
#name ⇒ Object
57 58 59 |
# File 'lib/magic_grid/column.rb', line 57 def name @col[:col] end |
#reader ⇒ Object
66 67 68 |
# File 'lib/magic_grid/column.rb', line 66 def reader @col[:to_s] || @col[:col] end |
#sortable? ⇒ Boolean
45 46 47 |
# File 'lib/magic_grid/column.rb', line 45 def sortable? not custom_sql.blank? end |