Class: Datagrid::Columns::Column
- Inherits:
-
Object
- Object
- Datagrid::Columns::Column
- Defined in:
- lib/datagrid/columns/column.rb
Defined Under Namespace
Classes: ResponseFormat
Instance Attribute Summary collapse
-
#data_block ⇒ Object
Returns the value of attribute data_block.
-
#grid_class ⇒ Object
Returns the value of attribute grid_class.
-
#html_block ⇒ Object
Returns the value of attribute html_block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #block ⇒ Object
- #data? ⇒ Boolean
- #data_value(model, grid) ⇒ Object
- #enabled?(grid) ⇒ Boolean
- #generic_value(model, grid) ⇒ Object
- #header ⇒ Object
- #html? ⇒ Boolean
- #html_value(context, asset, grid) ⇒ Object
-
#initialize(grid_class, name, query, options = {}, &block) ⇒ Column
constructor
A new instance of Column.
- #inspect ⇒ Object
- #label ⇒ Object
- #mandatory? ⇒ Boolean
- #order ⇒ Object
- #order_by_value(model, grid) ⇒ Object
- #order_by_value? ⇒ Boolean
- #order_desc ⇒ Object
- #supports_order? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(grid_class, name, query, options = {}, &block) ⇒ Column
Returns a new instance of Column.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/datagrid/columns/column.rb', line 30 def initialize(grid_class, name, query, = {}, &block) self.grid_class = grid_class self.name = name.to_sym self. = if [:html] == true self.html_block = block else self.data_block = block if [:html].is_a? Proc self.html_block = [:html] end end self.query = query [:if] = convert_option_to_proc([:if]) [:unless] = convert_option_to_proc([:unless]) end |
Instance Attribute Details
#data_block ⇒ Object
Returns the value of attribute data_block.
28 29 30 |
# File 'lib/datagrid/columns/column.rb', line 28 def data_block @data_block end |
#grid_class ⇒ Object
Returns the value of attribute grid_class.
28 29 30 |
# File 'lib/datagrid/columns/column.rb', line 28 def grid_class @grid_class end |
#html_block ⇒ Object
Returns the value of attribute html_block.
28 29 30 |
# File 'lib/datagrid/columns/column.rb', line 28 def html_block @html_block end |
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/datagrid/columns/column.rb', line 28 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
28 29 30 |
# File 'lib/datagrid/columns/column.rb', line 28 def @options end |
#query ⇒ Object
Returns the value of attribute query.
28 29 30 |
# File 'lib/datagrid/columns/column.rb', line 28 def query @query end |
Instance Method Details
#block ⇒ Object
121 122 123 124 |
# File 'lib/datagrid/columns/column.rb', line 121 def block Datagrid::Utils.warn_once("Datagrid::Columns::Column#block is deprecated. Use #html_block or #data_block instead") data_block end |
#data? ⇒ Boolean
96 97 98 |
# File 'lib/datagrid/columns/column.rb', line 96 def data? self.data_block != nil end |
#data_value(model, grid) ⇒ Object
48 49 50 51 |
# File 'lib/datagrid/columns/column.rb', line 48 def data_value(model, grid) # backward compatibility method grid.data_value(name, model) end |
#enabled?(grid) ⇒ Boolean
104 105 106 |
# File 'lib/datagrid/columns/column.rb', line 104 def enabled?(grid) (![:if] || ([:if] && [:if].call(grid))) && ![:unless] || ([:unless] && ![:unless].call(grid)) end |
#generic_value(model, grid) ⇒ Object
126 127 128 |
# File 'lib/datagrid/columns/column.rb', line 126 def generic_value(model, grid) grid.generic_value(self, model) end |
#header ⇒ Object
58 59 60 61 |
# File 'lib/datagrid/columns/column.rb', line 58 def header self.[:header] || I18n.translate(self.name, :scope => "datagrid.#{self.grid_class.param_name}.columns", :default => self.name.to_s.humanize ) end |
#html? ⇒ Boolean
92 93 94 |
# File 'lib/datagrid/columns/column.rb', line 92 def html? [:html] != false end |
#html_value(context, asset, grid) ⇒ Object
116 117 118 |
# File 'lib/datagrid/columns/column.rb', line 116 def html_value(context, asset, grid) grid.html_value(name, context, asset) end |
#inspect ⇒ Object
108 109 110 |
# File 'lib/datagrid/columns/column.rb', line 108 def inspect "#<Datagrid::Columns::Column #{grid_class}##{name} #{.inspect}>" end |
#label ⇒ Object
54 55 56 |
# File 'lib/datagrid/columns/column.rb', line 54 def label self.[:label] end |
#mandatory? ⇒ Boolean
100 101 102 |
# File 'lib/datagrid/columns/column.rb', line 100 def mandatory? !! [:mandatory] end |
#order ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/datagrid/columns/column.rb', line 63 def order if .has_key?(:order) && [:order] != true self.[:order] else grid_class.driver.default_order(grid_class.scope, name) end end |
#order_by_value(model, grid) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/datagrid/columns/column.rb', line 75 def order_by_value(model, grid) if [:order_by_value] == true grid.data_value(self, model) else Datagrid::Utils.apply_args(model, grid, &[:order_by_value]) end end |
#order_by_value? ⇒ Boolean
83 84 85 |
# File 'lib/datagrid/columns/column.rb', line 83 def order_by_value? !! [:order_by_value] end |
#order_desc ⇒ Object
87 88 89 90 |
# File 'lib/datagrid/columns/column.rb', line 87 def order_desc return nil unless order self.[:order_desc] end |
#supports_order? ⇒ Boolean
71 72 73 |
# File 'lib/datagrid/columns/column.rb', line 71 def supports_order? order || order_by_value? end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/datagrid/columns/column.rb', line 112 def to_s header end |