Created
May 28, 2013 09:09
-
-
Save Arkham/5661524 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 SearchPlaces | |
include ActiveModel::Validations | |
include ActiveModel::Conversion | |
extend ActiveModel::Naming | |
attr_accessor :lat, :lng, :distance, :address | |
attr_accessor :query | |
attr_accessor :type_id | |
attr_accessor :category_id | |
def initialize(attributes) | |
attributes ||= {} | |
attributes.each do |name, value| | |
send("#{name}=", value) | |
end | |
end | |
def persisted? | |
false | |
end | |
def scope | |
scope = Place.published | |
if lat && lng && distance | |
scope = scope.near([lat, lng], distance) | |
end | |
if query.present? | |
scope = scope.matching(query) | |
end | |
if type_id.present? | |
scope = scope.of_type(type_id) | |
end | |
if category_id.present? | |
scope = scope.of_category(category_id) | |
end | |
scope | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment