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
- #append_preload(relation) ⇒ Object
- #data? ⇒ Boolean
- #data_value(model, grid) ⇒ Object
- #driver ⇒ 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
- #mandatory_explicitly_set? ⇒ Boolean
- #order ⇒ Object
- #order_by_value(model, grid) ⇒ Object
- #order_by_value? ⇒ Boolean
- #order_desc ⇒ Object
- #preload ⇒ Object
- #supports_order? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(grid_class, name, query, options = {}, &block) ⇒ Column
Returns a new instance of Column.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/datagrid/columns/column.rb', line 36 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 end |
Instance Attribute Details
#data_block ⇒ Object
Returns the value of attribute data_block.
34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 34 def data_block @data_block end |
#grid_class ⇒ Object
Returns the value of attribute grid_class.
34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 34 def grid_class @grid_class end |
#html_block ⇒ Object
Returns the value of attribute html_block.
34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 34 def html_block @html_block end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 34 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 34 def @options end |
#query ⇒ Object
Returns the value of attribute query.
34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 34 def query @query end |
Instance Method Details
#append_preload(relation) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/datagrid/columns/column.rb', line 136 def append_preload(relation) return relation unless preload if preload.respond_to?(:call) return relation unless preload if preload.arity == 1 preload.call(relation) else relation.instance_exec(&preload) end else driver.default_preload(relation, preload) end end |
#data? ⇒ Boolean
103 104 105 |
# File 'lib/datagrid/columns/column.rb', line 103 def data? self.data_block != nil end |
#data_value(model, grid) ⇒ Object
52 53 54 55 |
# File 'lib/datagrid/columns/column.rb', line 52 def data_value(model, grid) # backward compatibility method grid.data_value(name, model) end |
#driver ⇒ Object
161 162 163 |
# File 'lib/datagrid/columns/column.rb', line 161 def driver grid_class.driver end |
#enabled?(grid) ⇒ Boolean
115 116 117 |
# File 'lib/datagrid/columns/column.rb', line 115 def enabled?(grid) ::Datagrid::Utils.process_availability(grid, [:if], [:unless]) end |
#generic_value(model, grid) ⇒ Object
132 133 134 |
# File 'lib/datagrid/columns/column.rb', line 132 def generic_value(model, grid) grid.generic_value(self, model) end |
#header ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/datagrid/columns/column.rb', line 62 def header if header = [:header] Datagrid::Utils.callable(header) else Datagrid::Utils.translate_from_namespace(:columns, grid_class, name) end end |
#html? ⇒ Boolean
99 100 101 |
# File 'lib/datagrid/columns/column.rb', line 99 def html? [:html] != false end |
#html_value(context, asset, grid) ⇒ Object
127 128 129 |
# File 'lib/datagrid/columns/column.rb', line 127 def html_value(context, asset, grid) grid.html_value(name, context, asset) end |
#inspect ⇒ Object
119 120 121 |
# File 'lib/datagrid/columns/column.rb', line 119 def inspect "#<#{self.class} #{grid_class}##{name} #{.inspect}>" end |
#label ⇒ Object
58 59 60 |
# File 'lib/datagrid/columns/column.rb', line 58 def label self.[:label] end |
#mandatory? ⇒ Boolean
107 108 109 |
# File 'lib/datagrid/columns/column.rb', line 107 def mandatory? !! [:mandatory] end |
#mandatory_explicitly_set? ⇒ Boolean
111 112 113 |
# File 'lib/datagrid/columns/column.rb', line 111 def mandatory_explicitly_set? .key?(:mandatory) end |
#order ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/datagrid/columns/column.rb', line 70 def order if .has_key?(:order) && [:order] != true self.[:order] else driver.default_order(grid_class.scope, name) end end |
#order_by_value(model, grid) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/datagrid/columns/column.rb', line 82 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
90 91 92 |
# File 'lib/datagrid/columns/column.rb', line 90 def order_by_value? !! [:order_by_value] end |
#order_desc ⇒ Object
94 95 96 97 |
# File 'lib/datagrid/columns/column.rb', line 94 def order_desc return nil unless order self.[:order_desc] end |
#preload ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/datagrid/columns/column.rb', line 150 def preload preload = [:preload] if preload == true && driver.can_preload?(grid_class.scope, name) name else preload end end |
#supports_order? ⇒ Boolean
78 79 80 |
# File 'lib/datagrid/columns/column.rb', line 78 def supports_order? order || order_by_value? end |
#to_s ⇒ Object
123 124 125 |
# File 'lib/datagrid/columns/column.rb', line 123 def to_s header end |