Class: Symphonia::QueryColumns::AttributeColumn

Inherits:
GenericColumn show all
Defined in:
lib/symphonia/query_columns/attribute_column.rb

Instance Attribute Summary collapse

Attributes inherited from GenericColumn

#default, #header, #includes, #joins, #model, #name, #preload, #query, #sort, #sort_definition

Instance Method Summary collapse

Methods inherited from GenericColumn

#css_classes, #default?, #header?, #inspect, #sort?, #sum, #sum_value, #summarize?, #title, #value

Constructor Details

#initialize(attribute, query, options = {}) ⇒ AttributeColumn

Returns a new instance of AttributeColumn.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/symphonia/query_columns/attribute_column.rb', line 11

def initialize(attribute, query, options={})
  @attribute = attribute
  @name = attribute.name
  @query = query
  @model = query.model
  @options = options

  @includes = options.delete(:includes) || reference? && [@name] || []
  @preload = options.delete(:preload) || reference? && [@name] || []
  @joins = Array(options.delete(:joins)) || []
  @sort_definition = attribute.sort_column
  @sort = attribute.sort?
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5

def attribute
  @attribute
end

#header=(value) ⇒ Object (writeonly)

Sets the attribute header

Parameters:

  • value

    the value to set the attribute header to.



7
8
9
# File 'lib/symphonia/query_columns/attribute_column.rb', line 7

def header=(value)
  @header = value
end

#no_headerObject

Returns the value of attribute no_header.



6
7
8
# File 'lib/symphonia/query_columns/attribute_column.rb', line 6

def no_header
  @no_header
end

#sort=(value) ⇒ Object (writeonly)

Sets the attribute sort

Parameters:

  • value

    the value to set the attribute sort to.



7
8
9
# File 'lib/symphonia/query_columns/attribute_column.rb', line 7

def sort=(value)
  @sort = value
end

#sort_optionsObject

Returns the value of attribute sort_options.



6
7
8
# File 'lib/symphonia/query_columns/attribute_column.rb', line 6

def sort_options
  @sort_options
end

Instance Method Details

#format_value(view, entity) ⇒ Object

def header(table_header_tag)

if @header === false
  table_header_tag.th(@name, '', sort: false)
else
  table_header_tag.th(@name, title, {sort: @sort.nil?, sort_options: (sort_options || {}).merge({column: sort_column_name})})
end

end



37
38
39
# File 'lib/symphonia/query_columns/attribute_column.rb', line 37

def format_value(view, entity)
  @attribute.format(view, entity)
end

#reference?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/symphonia/query_columns/attribute_column.rb', line 25

def reference?
  @attribute.is_a?(Symphonia::ModelAttributes::ReferenceAttribute)
end