Class: ActiveList::Definition::AttributeColumn
- Inherits:
-
DataColumn
- Object
- AbstractColumn
- DataColumn
- ActiveList::Definition::AttributeColumn
- Defined in:
- lib/active_list/definition/attribute_column.rb
Direct Known Subclasses
Constant Summary
Constants inherited from DataColumn
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#computation_method ⇒ Object
readonly
Returns the value of attribute computation_method.
-
#label_method ⇒ Object
readonly
Returns the value of attribute label_method.
-
#sort_column ⇒ Object
readonly
Returns the value of attribute sort_column.
-
#value_method ⇒ Object
readonly
Returns the value of attribute value_method.
Attributes inherited from AbstractColumn
#condition, #id, #name, #options, #table
Instance Method Summary collapse
-
#class_name ⇒ Object
Returns the class name of the used model.
- #computable? ⇒ Boolean
-
#datum_code(record = 'record_of_the_death', child = false) ⇒ Object
Code for rows.
- #datum_value(record = 'record of the death', child = false) ⇒ Object
- #enumerize? ⇒ Boolean
- #get_sort_column ⇒ Object
-
#initialize(table, name, options = {}) ⇒ AttributeColumn
constructor
A new instance of AttributeColumn.
- #sort_expression ⇒ Object
- #sortable? ⇒ Boolean
Methods inherited from DataColumn
#currency_for, #datatype, #exportable?, #exporting_datum_code, #header_code, #limit, #numeric?, #record_expr, #state_machine?
Methods inherited from AbstractColumn
#check_options!, #exportable?, #header_code, #hidden?, #short_id, #unique_id
Constructor Details
#initialize(table, name, options = {}) ⇒ AttributeColumn
Returns a new instance of AttributeColumn.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_list/definition/attribute_column.rb', line 6 def initialize(table, name, = {}) super(table, name, ) @label_method = ([:label_method] || @name).to_sym @value_method = if [:value_method].present? [:value_method].to_sym else @label_method.to_s.gsub('human_', '').to_sym end @sort_column = get_sort_column @computation_method = [:on_select] @column = @table.model.columns_hash[@label_method.to_s] end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
4 5 6 |
# File 'lib/active_list/definition/attribute_column.rb', line 4 def column @column end |
#computation_method ⇒ Object (readonly)
Returns the value of attribute computation_method.
4 5 6 |
# File 'lib/active_list/definition/attribute_column.rb', line 4 def computation_method @computation_method end |
#label_method ⇒ Object (readonly)
Returns the value of attribute label_method.
4 5 6 |
# File 'lib/active_list/definition/attribute_column.rb', line 4 def label_method @label_method end |
#sort_column ⇒ Object (readonly)
Returns the value of attribute sort_column.
4 5 6 |
# File 'lib/active_list/definition/attribute_column.rb', line 4 def sort_column @sort_column end |
#value_method ⇒ Object (readonly)
Returns the value of attribute value_method.
4 5 6 |
# File 'lib/active_list/definition/attribute_column.rb', line 4 def value_method @value_method end |
Instance Method Details
#class_name ⇒ Object
Returns the class name of the used model
67 68 69 |
# File 'lib/active_list/definition/attribute_column.rb', line 67 def class_name "RECORD.class.name.tableize".c end |
#computable? ⇒ Boolean
75 76 77 |
# File 'lib/active_list/definition/attribute_column.rb', line 75 def computable? !computation_method.nil? end |
#datum_code(record = 'record_of_the_death', child = false) ⇒ Object
Code for rows
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_list/definition/attribute_column.rb', line 20 def datum_code(record = 'record_of_the_death', child = false) code = '' code = if child if @options[:children].is_a?(FalseClass) 'nil' else "#{record}.#{table.[:children]}.#{@options[:children] || @label_method}" end else "#{record}.#{@label_method}" end code.c end |
#datum_value(record = 'record of the death', child = false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_list/definition/attribute_column.rb', line 34 def datum_value(record = 'record of the death', child = false) code = '' code = if child if @options[:childer].is_a?(FalseClass) 'nil' else "#{record}.#{table.[:children]}.#{@options[:children] || @value_method}" end else "#{record}.#{@value_method}" end code.c end |
#enumerize? ⇒ Boolean
79 80 81 82 |
# File 'lib/active_list/definition/attribute_column.rb', line 79 def enumerize? table.model.respond_to?(:enumerized_attributes) && !table.model.enumerized_attributes[@label_method].nil? end |
#get_sort_column ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_list/definition/attribute_column.rb', line 48 def get_sort_column selects = @table.[:select] || {} selects_label = selects.find { |sql_name, name| name.to_s == @label_method.to_s }&.last selects_name = selects.find { |sql_name, name| name.to_s == @name.to_s }&.last if (selects_label || selects_name) && [:sort].blank? sort_column = (selects_label || selects_name) else sort_column = [:sort] sort_column ||= if @table.model.columns_hash[@label_method.to_s] @label_method elsif @table.model.columns_hash[@name.to_s] @name end sort_column &&= "#{@table.model.table_name}.#{sort_column}" end sort_column end |
#sort_expression ⇒ Object
84 85 86 |
# File 'lib/active_list/definition/attribute_column.rb', line 84 def sort_expression @sort_column end |
#sortable? ⇒ Boolean
71 72 73 |
# File 'lib/active_list/definition/attribute_column.rb', line 71 def sortable? !sort_column.nil? end |