class PaginationSearch::AttributeSet
Constants
- Attribute
Public Class Methods
new(base_class, attribute_locations)
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 13 def initialize(base_class, attribute_locations) @base_class = base_class @attributes = {} build_attributes(attribute_locations) end
Public Instance Methods
[](name)
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 19 def [](name) @attributes[name] end
foreign_attributes()
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 23 def foreign_attributes @attributes.values.select do |attribute| foreign?(attribute.association_name) end end
text_attributes()
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 29 def text_attributes @attributes.values.select do |attribute| text?(attribute.type) end end
Private Instance Methods
arel_table_for_association(association)
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 52 def arel_table_for_association(association) if foreign?(association) table_name = @base_class.reflections[association.to_s].plural_name Arel::Table.new(table_name) else @base_class.arel_table end end
build_attributes(attribute_locations)
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 45 def build_attributes(attribute_locations) attribute_locations.each do |key, value| arel_table = arel_table_for_association(value[:association]) @attributes[key] = Attribute.new(key, arel_table, value[:association], value[:column], value[:type]) end end
foreign?(association)
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 37 def foreign?(association) association != :base end
text?(type)
click to toggle source
# File lib/pagination_search/attribute_set.rb, line 41 def text?(type) type == :text end