Skip to content

Instantly share code, notes, and snippets.

@factore
Created June 27, 2012 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save factore/3005563 to your computer and use it in GitHub Desktop.
Save factore/3005563 to your computer and use it in GitHub Desktop.
class DocumentFilter
def self.find(klass, options = {})
document_filter = self.new(klass, options)
document_filter.results
end
def initialize(klass, options = {})
@document_class = klass.to_s.capitalize.constantize
@options = options.symbolize_keys!
@documents = @document_class.where("1 = 1")
end
def results
@documents = @documents.send(@options[:estimate_type]) if @options[:estimate_type]
if @options[:aasm_current_state]
@documents = @documents.where(:aasm_current_state => @options[:aasm_current_state])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment