Module: PrismicRails::QueryService
- Defined in:
- lib/prismic_rails/services/query_service.rb
Overview
The PrismicRails::QueryService is a small helper to query the Prismic API with support for query types. It also helps to create the right query for your i18n support.
Class Method Summary collapse
-
.by_type(type, options = {}) ⇒ Object
Query the Prismic API by type ==== Examples PrismicRails::QueryService.type(‘blog-post’).
-
.query(options = {}) ⇒ Object
Query the Prismic API.
Class Method Details
.by_type(type, options = {}) ⇒ Object
Query the Prismic API by type
Examples
PrismicRails::QueryService.type('blog-post')
This returns a Prismic::Response with all the (published) documents of the type ‘blog-post’
PrismicRails::QueryService.type('blog-post', {lang: 'en'}
This gets all the (published) documents of the type ‘blog-post’ in english as a Prismic::Response and wraps it around with a PrismicRails::Result
21 22 23 24 25 26 27 28 29 |
# File 'lib/prismic_rails/services/query_service.rb', line 21 def by_type(type, = {}) type_query = {'document.type': type} if [:q] [:q].merge(type_query) else [:q] = type_query end query() end |
.query(options = {}) ⇒ Object
Query the Prismic API
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prismic_rails/services/query_service.rb', line 32 def query( = {}) match_language() if [:lang] predicates = [] if q = .delete(:q) q.each do |key, value| predicates << Prismic::Predicates.at(key, value) end end response = api.query(predicates, ) PrismicRails::Result.new(response) end |