Created
August 27, 2013 00:21
-
-
Save BenEddy/6348309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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