Class: ActiveList::Definition::AttributeColumn

Inherits:
DataColumn show all
Defined in:
lib/active_list/definition/attribute_column.rb

Direct Known Subclasses

StatusColumn

Constant Summary

Constants inherited from DataColumn

DataColumn::LABELS_COLUMNS

Instance Attribute Summary collapse

Attributes inherited from AbstractColumn

#id, #name, #options, #table

Instance Method Summary collapse

Methods inherited from DataColumn

#datatype, #exportable?, #exporting_datum_code, #header_code, #limit, #numeric?, #record_expr, #sortable?

Methods inherited from AbstractColumn

#check_options!, #exportable?, #header_code, #hidden?, #short_id, #sortable?, #unique_id

Constructor Details

#initialize(table, name, options = {}) ⇒ AttributeColumn

Returns a new instance of AttributeColumn.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_list/definition/attribute_column.rb', line 9

def initialize(table, name, options = {})
  super(table, name, options)
  @label_method = (options[:label_method] || @name).to_sym
  unless @sort_column = options[:sort]
    if @table.model.columns_hash[@label_method]
      @sort_column = @label_method
    elsif @table.model.columns_hash[@name]
      @sort_column = @name
    else
      @sort_column = :id
    end
  end
  @column  = @table.model.columns_hash[@label_method.to_s]
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



7
8
9
# File 'lib/active_list/definition/attribute_column.rb', line 7

def column
  @column
end

#label_methodObject (readonly)

Returns the value of attribute label_method.



7
8
9
# File 'lib/active_list/definition/attribute_column.rb', line 7

def label_method
  @label_method
end

#sort_columnObject (readonly)

Returns the value of attribute sort_column.



7
8
9
# File 'lib/active_list/definition/attribute_column.rb', line 7

def sort_column
  @sort_column
end

Instance Method Details

#class_nameObject

Returns the class name of the used model



40
41
42
# File 'lib/active_list/definition/attribute_column.rb', line 40

def class_name
  return self.table.model.name
end

#datum_code(record = 'record_of_the_death', child = false) ⇒ Object

Code for rows



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_list/definition/attribute_column.rb', line 25

def datum_code(record = 'record_of_the_death', child = false)
  code = ""
  if child
    if @options[:children].is_a?(FalseClass)
      code = "nil"
    else
      code = "#{record}.#{table.options[:children]}.#{@options[:children] || @label_method}"
    end
  else
    code = "#{record}.#{@label_method}"
  end
  return code.c
end

#enumerize?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'lib/active_list/definition/attribute_column.rb', line 44

def enumerize?
  self.table.model.send(@label_method).send(:values)
  return true
rescue
  return false
end

#sort_expressionObject



51
52
53
# File 'lib/active_list/definition/attribute_column.rb', line 51

def sort_expression
  "#{@table.model.table_name}.#{@sort_column}"
end