Class: Aerogel::Admin::TableBuilder::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/aerogel/admin/table_builder.rb

Constant Summary collapse

KNOWN_OPTIONS =
[ :label ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, field, options = {}, &block) ⇒ Column

Returns a new instance of Column.



62
63
64
65
66
67
68
# File 'lib/aerogel/admin/table_builder.rb', line 62

def initialize( table, field, options = {}, &block )
  self.table = table
  self.field = field
  self.options = options
  self.block = block
  self.label = self.options[:label] || self.field.to_sym
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



58
59
60
# File 'lib/aerogel/admin/table_builder.rb', line 58

def block
  @block
end

#fieldObject

Returns the value of attribute field.



58
59
60
# File 'lib/aerogel/admin/table_builder.rb', line 58

def field
  @field
end

#labelObject

Returns the value of attribute label.



58
59
60
# File 'lib/aerogel/admin/table_builder.rb', line 58

def label
  @label
end

#optionsObject

Returns the value of attribute options.



58
59
60
# File 'lib/aerogel/admin/table_builder.rb', line 58

def options
  @options
end

#tableObject

Returns the value of attribute table.



58
59
60
# File 'lib/aerogel/admin/table_builder.rb', line 58

def table
  @table
end

Instance Method Details

#html_paramsObject

Renders html params for column cells



88
89
90
91
92
# File 'lib/aerogel/admin/table_builder.rb', line 88

def html_params
  attrs = @options.except( *KNOWN_OPTIONS )
  attrs = attrs.deep_merge( @options[:html_params] ) if @options.key? :html_params
  attrs.to_html_params
end

#human_labelObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aerogel/admin/table_builder.rb', line 70

def human_label
  if label.is_a? Symbol
    if table.object.respond_to? :human_attribute_name
      table.object.human_attribute_name label, default: label
    elsif table.object.respond_to?( :first ) &&  table.object.first.class.respond_to?( :human_attribute_name )
      table.object.first.class.human_attribute_name label, default: label
    else
      I18n.t label
    end
  elsif label.is_a? String
    label
  else
    label.to_s.humanize
  end
end