class AttrSearchableGrammar::Attributes::Collection
Attributes
key[R]
model[R]
Public Class Methods
new(model, key)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 9 def initialize(model, key) raise(AttrSearchable::UnknownColumn, "Unknown column #{key}") unless model.searchable_attributes[key] @model = model @key = key end
Public Instance Methods
==(other)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 20 def ==(other) other.is_a?(self.class) && [model, key] == [other.model, other.key] end
alias_for(table)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 65 def alias_for(table) (model.searchable_attribute_aliases[table] && table) || klass_for(table).table_name end
attribute_for(attribute_definition)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 69 def attribute_for(attribute_definition) table, column = attribute_definition.split(".") klass = klass_for(table) raise(AttrSearchable::UnknownAttribute, "Unknown attribute #{attribute_definition}") unless klass.columns_hash[column] Attributes.const_get(klass.columns_hash[column].type.to_s.classify).new(klass.arel_table.alias(alias_for(table))[column], klass, options) end
attributes()
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 54 def attributes @attributes ||= model.searchable_attributes[key].collect { |attribute_definition| attribute_for attribute_definition } end
compatible?(value)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 46 def compatible?(value) attributes.all? { |attribute| attribute.compatible? value } end
eql?(other)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 16 def eql?(other) self == other end
fulltext?()
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 42 def fulltext? (model.searchable_attribute_options[key] || {})[:type] == :fulltext end
hash()
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 24 def hash [model, key].hash end
klass_for(table)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 58 def klass_for(table) klass = model.searchable_attribute_aliases[table] klass ||= table model.reflections[klass.to_sym] ? model.reflections[klass.to_sym].klass : klass.classify.constantize end
matches(value)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 34 def matches(value) if fulltext? AttrSearchableGrammar::Nodes::MatchesFulltext.new self, value.to_s else attributes.collect! { |attribute| attribute.matches value }.inject(:or) end end
options()
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 50 def options model.searchable_attribute_options[key] end