Class: ActiveList::Definition::DataColumn

Inherits:
AbstractColumn show all
Defined in:
lib/active_list/definition/data_column.rb

Direct Known Subclasses

AssociationColumn, AttributeColumn

Constant Summary collapse

LABELS_COLUMNS =
[:full_name, :label, :name, :number, :coordinate].freeze

Instance Attribute Summary

Attributes inherited from AbstractColumn

#id, #name, #options, #table

Instance Method Summary collapse

Methods inherited from AbstractColumn

#check_options!, #computable?, #hidden?, #initialize, #short_id, #unique_id

Constructor Details

This class inherits a constructor from ActiveList::Definition::AbstractColumn

Instance Method Details

#currency_for(record) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/active_list/definition/data_column.rb', line 45

def currency_for(record)
  currency = options[:currency]
  if currency
    currency = currency[:body] if currency.is_a?(Hash)
    currency = :currency if currency.is_a?(TrueClass)
    currency = "#{record}.#{currency}".c if currency.is_a?(Symbol)
  end
  currency
end

#datatypeObject

Returns the data type of the column if the column is in the database



37
38
39
# File 'lib/active_list/definition/data_column.rb', line 37

def datatype
  @options[:datatype] || (@column ? @column.type : nil)
end

#enumerize?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/active_list/definition/data_column.rb', line 41

def enumerize?
  false
end

#exportable?Boolean

Defines if column is exportable

Returns:

  • (Boolean)


69
70
71
# File 'lib/active_list/definition/data_column.rb', line 69

def exportable?
  true
end

#exporting_datum_code(record = 'record_of_the_death', noview = false) ⇒ Object

Code for exportation



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_list/definition/data_column.rb', line 15

def exporting_datum_code(record = 'record_of_the_death', noview = false)
  datum = datum_code(record)
  if datatype == :boolean
    datum = "(#{datum} ? ::I18n.translate('list.export.true_value') : ::I18n.translate('list.export.false_value'))"
  elsif datatype == :date
    datum = "(#{datum}.nil? ? '' : #{datum}.l)"
  elsif datatype == :decimal && !noview
    currency = currency_for(record)
    datum = "(#{datum}.nil? ? '' : #{datum}.l(#{'currency: ' + currency.inspect if currency}))"
  elsif @name.to_s.match(/(^|\_)currency$/) && datatype == :string
    datum = "(Nomen::Currencies[#{datum}] ? Nomen::Currencies[#{datum}].human_name : '')"
  elsif @name.to_s.match(/(^|\_)country$/) && datatype == :string
    datum = "(Nomen::Countries[#{datum}] ? Nomen::Countries[#{datum}].human_name : '')"
  elsif @name.to_s.match(/(^|\_)language$/) && datatype == :string
    datum = "(Nomen::Languages[#{datum}] ? Nomen::Languages[#{datum}].human_name : '')"
  elsif enumerize?
    datum = "(#{datum}.nil? ? '' : #{datum}.text)"
  end
  datum
end

#header_codeObject



6
7
8
9
10
11
12
# File 'lib/active_list/definition/data_column.rb', line 6

def header_code
  if @options[:label]
    "#{@options[:label].to_s.strip.inspect}.t(scope: 'labels')".c
  else
    "#{@table.model.name}.human_attribute_name(#{@name.inspect})".c
  end
end

#limitObject

Returns the size/length of the column if the column is in the database



64
65
66
# File 'lib/active_list/definition/data_column.rb', line 64

def limit
  @column[:limit] if @column
end

#numeric?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/active_list/definition/data_column.rb', line 59

def numeric?
  [:decimal, :integer, :float, :numeric].include? datatype
end

#record_expr(record = 'record_of_the_death') ⇒ Object

Generate code in order to get the (foreign) record of the column



81
82
83
# File 'lib/active_list/definition/data_column.rb', line 81

def record_expr(record = 'record_of_the_death')
  record
end

#sort_expressionObject

Raises:

  • (NotImplementedError)


85
86
87
# File 'lib/active_list/definition/data_column.rb', line 85

def sort_expression
  raise NotImplementedError, 'sort_expression must be implemented'
end

#sortable?Boolean

Check if a column is sortable

Returns:

  • (Boolean)


74
75
76
77
78
# File 'lib/active_list/definition/data_column.rb', line 74

def sortable?
  true
  # not self.action? and
  # !options[:through] && [email protected]?
end

#state_machine?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/active_list/definition/data_column.rb', line 55

def state_machine?
  false
end