Class: Symphonia::QueryColumns::AttributeColumn

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#includesObject (readonly)

Returns the value of attribute includes.



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

def includes
  @includes
end

#joinsObject (readonly)

Returns the value of attribute joins.



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

def joins
  @joins
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
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

#preloadObject (readonly)

Returns the value of attribute preload.



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

def preload
  @preload
end

#queryObject (readonly)

Returns the value of attribute query.



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

def query
  @query
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_column_name=(value) ⇒ Object

Sets the attribute sort_column_name

Parameters:

  • value

    the value to set the attribute sort_column_name to.



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

def sort_column_name=(value)
  @sort_column_name = value
end

#sort_definitionObject



53
54
55
56
57
# File 'lib/symphonia/query_columns/attribute_column.rb', line 53

def sort_definition
  return nil unless sort?

  @sort_definition ||= SortableTable::SortColumnCustomDefinition.new(@name, { asc: "#{sort_column_name} asc", desc: "#{sort_column_name} desc" })
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

#css_classesObject



73
74
75
# File 'lib/symphonia/query_columns/attribute_column.rb', line 73

def css_classes
  @name.to_s
end

#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

#header?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/symphonia/query_columns/attribute_column.rb', line 45

def header?
  !(@header == false)
end

#inspectObject



77
78
79
# File 'lib/symphonia/query_columns/attribute_column.rb', line 77

def inspect
  "#<#{self.class.name} name='#{name}' options=#{@options.inspect}>"
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

#sort?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/symphonia/query_columns/attribute_column.rb', line 49

def sort?
  !(@sort == false)
end

#sumObject



67
68
69
70
71
# File 'lib/symphonia/query_columns/attribute_column.rb', line 67

def sum
  return nil unless summarize?

  @sum ||= query.entities.sum(name)
end

#sum_value(view) ⇒ Object



63
64
65
# File 'lib/symphonia/query_columns/attribute_column.rb', line 63

def sum_value(view)
  format_value(view, OpenStruct.new(name => sum))
end

#summarize?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/symphonia/query_columns/attribute_column.rb', line 41

def summarize?
  false
end

#value(entity) ⇒ Object



59
60
61
# File 'lib/symphonia/query_columns/attribute_column.rb', line 59

def value(entity)
  entity.send(name)
end