Skip to content

Instantly share code, notes, and snippets.

@BenEddy
Created August 27, 2013 00:21
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 BenEddy/6348309 to your computer and use it in GitHub Desktop.
Save BenEddy/6348309 to your computer and use it in GitHub Desktop.
class UserSearch
attr_reader :name, :email
def initialize(options = {})
@name = options[:name]
@email = options[:email]
end
def results
scope = User.scoped
scope = scope.name_matching(name) if scope_by_name?
scope = scope.email_matching(email) if scope_by_email?
scope
end
private
def scope_by_name?
name.present?
end
def scope_by_email?
email.present?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment