# File lib/thinking_sphinx/property.rb, line 5 def initialize(source, columns, options = {}) @source = source @model = source.model @columns = Array(columns) @associations = {} raise "Cannot define a field or attribute in #{source.model.name} with no columns. Maybe you are trying to index a field with a reserved name (id, name). You can fix this error by using a symbol rather than a bare name (:id instead of id)." if @columns.empty? || @columns.any? { |column| !column.respond_to?(:__stack) } @alias = options[:as] @faceted = options[:facet] @admin = options[:admin] @sortable = options[:sortable] || false @value_source = options[:value] @alias = @alias.to_sym unless @alias.blank? @columns.each { |col| @associations[col.__stack] = association_stack(col.__stack.clone).each { |assoc| assoc.join_to(source.base) } } end
# File lib/thinking_sphinx/property.rb, line 72 def admin? admin end
# File lib/thinking_sphinx/property.rb, line 80 def available? columns.any? { |column| column_available?(column) } end
# File lib/thinking_sphinx/property.rb, line 64 def changed?(instance) return true if is_string? || @columns.any? { |col| !col.__stack.empty? } @columns.any? { |col| instance.send("#{col.__name.to_s}_changed?") } end
# File lib/thinking_sphinx/property.rb, line 76 def public? !admin end
# File lib/thinking_sphinx/property.rb, line 41 def to_facet return nil unless @faceted ThinkingSphinx::Facet.new(self, @value_source) end
Get the part of the GROUP BY clause related to this attribute - if one is needed. If not, all you’ll get back is nil. The latter will happen if there isn’t actually a real column to get data from, or if there’s multiple data values (read: a has_many or has_and_belongs_to_many association).
# File lib/thinking_sphinx/property.rb, line 53 def to_group_sql case when is_many?, is_string?, ThinkingSphinx.use_group_by_shortcut? nil else @columns.collect { |column| column_with_prefix(column) } end end
Returns the unique name of the attribute - which is either the alias of the attribute, or the name of the only column - if there is only one. If there isn’t, there should be an alias. Else things probably won’t work. Consider yourself warned.
# File lib/thinking_sphinx/property.rb, line 33 def unique_name if @columns.length == 1 @alias || @columns.first.__name else @alias end end