Module: Rooftop::Queries::ClassMethods
- Defined in:
- lib/rooftop/queries/queries.rb
Instance Method Summary collapse
- #find_by!(args) ⇒ Object
-
#where(args) ⇒ Object
(also: #find_by)
We need to fix up the ‘where()` filter.
Instance Method Details
#find_by!(args) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/rooftop/queries/queries.rb', line 25 def find_by!(args) results = find_by(args) if results.present? results else raise Rooftop::RecordNotFound end end |
#where(args) ⇒ Object Also known as: find_by
We need to fix up the ‘where()` filter. WP-API expects a url format for filters like this: /?filter=foo.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rooftop/queries/queries.rb', line 10 def where(args) args = HashWithIndifferentAccess.new(args) # the fact that 'slug' is referred to in the db as 'name' is irritating. Let's fix that # in queries so we can specify {slug: "foo"} if args.keys.collect(&:to_sym).include?(:slug) args[:name] = args[:slug] args.delete(:slug) end filters = args.inject({}) {|hash,pair| hash["filter[#{pair.first}]"] = pair.last; hash} #Call the Her `where` method with our new filters super().where(filters) end |