module Facetious::FacetedClassMethods

These methods are made available on faceted ActiveRecord classes:

Private Class Methods

extended(other) click to toggle source

def some_faceted_class_private_method; end

# File lib/facetious.rb, line 128
def self.extended other
  other.instance_exec do
    include Facetious       # Add the instance methods
    self.class_attribute :facets
    self.facets ||= {}
  end
end

Public Instance Methods

find_by_facets(facet_values_hash) click to toggle source
# File lib/facetious.rb, line 121
def find_by_facets facet_values_hash
  self.class.where(where_clause_for_facets facet_values_hash)
end
where_clause_for_facets(facet_values_hash) click to toggle source
# File lib/facetious.rb, line 114
def where_clause_for_facets facet_values_hash
  facet_values_hash.map do |facet_name, value|
    facet = facets[facet_name.to_sym] or raise "#{self.name} has no search facet #{facet_name}"
    facet.condition_for value
  end*" AND "
end