Class: Datagrid::Columns::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/datagrid/columns/column.rb

Defined Under Namespace

Classes: ResponseFormat

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#data_blockObject (readonly)

Returns the value of attribute data_block.



48
49
50
# File 'lib/datagrid/columns/column.rb', line 48

def data_block
  @data_block
end

#grid_classClass (readonly)

Returns grid class where column is defined.

Returns:

  • (Class)

    grid class where column is defined



48
49
50
# File 'lib/datagrid/columns/column.rb', line 48

def grid_class
  @grid_class
end

#html_blockObject (readonly)

Returns the value of attribute html_block.



48
49
50
# File 'lib/datagrid/columns/column.rb', line 48

def html_block
  @html_block
end

#nameSymbol (readonly)

Returns column name.

Returns:

  • (Symbol)

    column name



48
# File 'lib/datagrid/columns/column.rb', line 48

attr_reader :grid_class, :name, :query, :options, :data_block, :html_block

#optionsHash<Symbol, Object> (readonly)

Returns column options.

Returns:

  • (Hash<Symbol, Object>)

    column options



48
# File 'lib/datagrid/columns/column.rb', line 48

attr_reader :grid_class, :name, :query, :options, :data_block, :html_block

#queryObject (readonly)

Returns the value of attribute query.



48
49
50
# File 'lib/datagrid/columns/column.rb', line 48

def query
  @query
end

Instance Method Details

#data?Boolean

Returns weather a column should be displayed in data.

Returns:

  • (Boolean)

    weather a column should be displayed in data



136
137
138
# File 'lib/datagrid/columns/column.rb', line 136

def data?
  data_block != nil
end

#data_value(model, grid) ⇒ Object

Deprecated.


76
77
78
79
# File 'lib/datagrid/columns/column.rb', line 76

def data_value(model, grid)
  # backward compatibility method
  grid.data_value(name, model)
end

#enabled?(grid) ⇒ Boolean

Returns weather a column is available via if and unless options.

Parameters:

Returns:

  • (Boolean)

    weather a column is available via if and unless options



165
166
167
# File 'lib/datagrid/columns/column.rb', line 165

def enabled?(grid)
  ::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
end

#headerString

Returns column header.

Returns:

  • (String)

    column header



87
88
89
90
91
92
93
# File 'lib/datagrid/columns/column.rb', line 87

def header
  if (header = options[:header])
    Datagrid::Utils.callable(header)
  else
    Datagrid::Utils.translate_from_namespace(:columns, grid_class, name)
  end
end

#html?Boolean

Returns weather a column should be displayed in HTML.

Returns:

  • (Boolean)

    weather a column should be displayed in HTML



131
132
133
# File 'lib/datagrid/columns/column.rb', line 131

def html?
  options[:html] != false
end

#html_classObject

Deprecated.

Use #tag_options instead.



151
152
153
154
155
156
# File 'lib/datagrid/columns/column.rb', line 151

def html_class
  Datagrid::Utils.warn_once(
    "Column#html_class is deprecated. Use Column#tag_options instead.",
  )
  options[:class]
end

#inspectString

Returns column console inspection.

Returns:

  • (String)

    column console inspection



170
171
172
# File 'lib/datagrid/columns/column.rb', line 170

def inspect
  "#<#{self.class} #{grid_class}##{name} #{options.inspect}>"
end

#labelObject

Deprecated.

Use #header instead



82
83
84
# File 'lib/datagrid/columns/column.rb', line 82

def label
  options[:label]
end

#mandatory?Boolean

Returns weather a column is explicitly marked mandatory.

Returns:

  • (Boolean)

    weather a column is explicitly marked mandatory



141
142
143
# File 'lib/datagrid/columns/column.rb', line 141

def mandatory?
  !!options[:mandatory]
end

#mandatory_explicitly_set?Boolean

Returns weather a mandatory option is explicitly set.

Returns:

  • (Boolean)

    weather a mandatory option is explicitly set



159
160
161
# File 'lib/datagrid/columns/column.rb', line 159

def mandatory_explicitly_set?
  options.key?(:mandatory)
end

#orderObject

Returns column order expression.

Returns:

  • (Object)

    column order expression



96
97
98
99
100
101
102
103
# File 'lib/datagrid/columns/column.rb', line 96

def order
  return nil if options[:order] == false
  if options.key?(:order) && options[:order] != true
    options[:order]
  else
    driver.default_order(grid_class.scope, name)
  end
end

#order_by_value?Boolean

Returns weather a column should be ordered by value.

Returns:

  • (Boolean)

    weather a column should be ordered by value



120
121
122
# File 'lib/datagrid/columns/column.rb', line 120

def order_by_value?
  !!options[:order_by_value]
end

#order_descObject



124
125
126
127
128
# File 'lib/datagrid/columns/column.rb', line 124

def order_desc
  return nil unless order

  options[:order_desc]
end

#preloadObject

Returns preload option value.

Returns:

  • (Object)

    preload option value



207
208
209
210
211
212
213
214
215
# File 'lib/datagrid/columns/column.rb', line 207

def preload
  preload = options[:preload]

  if preload == true && driver.can_preload?(grid_class.scope, name)
    name
  else
    preload
  end
end

#supports_order?Boolean

Returns weather column support order.

Returns:

  • (Boolean)

    weather column support order



106
107
108
# File 'lib/datagrid/columns/column.rb', line 106

def supports_order?
  !!order || order_by_value?
end

#tag_optionsHash<Symbol, Object>

Returns tag_options option value.

Returns:

  • (Hash<Symbol, Object>)

    tag_options option value



146
147
148
# File 'lib/datagrid/columns/column.rb', line 146

def tag_options
  options[:tag_options] || {}
end

#to_sString

Returns column header.

Returns:

  • (String)

    column header



175
176
177
# File 'lib/datagrid/columns/column.rb', line 175

def to_s
  header
end