Module: PrismicRails
- Defined in:
- lib/prismic_rails.rb,
lib/prismic_rails/railtie.rb,
lib/prismic_rails/version.rb,
lib/prismic_rails/content/result.rb,
lib/prismic_rails/content/document.rb,
lib/prismic_rails/content/fragment.rb,
lib/prismic_rails/content/nil_document.rb,
lib/prismic_rails/helpers/view_helpers.rb,
lib/prismic_rails/services/query_service.rb,
lib/prismic_rails/services/language_service.rb,
lib/generators/prismic_rails/install_generator.rb
Overview
:nodoc:
Defined Under Namespace
Modules: QueryService, ViewHelpers Classes: Config, Document, Fragment, InstallGenerator, LanguageService, NilDocument, NoPrismicAPIConnection, Railtie, Result
Constant Summary collapse
- VERSION =
:nodoc:
"1.3.2"
Class Method Summary collapse
-
.api ⇒ Object
Returns the Prismic::API Object or nil if prismic.io is down.
-
.caching_enabled? ⇒ Boolean
returns if the caching is enabled.
-
.config ⇒ Object
Initalize the Config class.
-
.configure {|self.config| ... } ⇒ Object
Set the configs.
-
.get_cached_ref ⇒ Object
Get the last cached master ref out of the rails cache if prismic is not available.
-
.get_ref ⇒ Object
Get the master ref from the Prismic::API object.
-
.ref ⇒ Object
Get the master ref of prismic account.
Class Method Details
.api ⇒ Object
Returns the Prismic::API Object or nil if prismic.io is down
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/prismic_rails.rb', line 38 def self.api begin Prismic.api(self.config.url, self.config.token) rescue Prismic::API::PrismicWSConnectionError, Prismic::API::BadPrismicResponseError, Prismic::API::PrismicWSAuthError, SocketError, Net::OpenTimeout raise NoPrismicAPIConnection end end |
.caching_enabled? ⇒ Boolean
returns if the caching is enabled
61 62 63 |
# File 'lib/prismic_rails.rb', line 61 def self.caching_enabled? PrismicRails.config.caching end |
.config ⇒ Object
Initalize the Config class
28 29 30 |
# File 'lib/prismic_rails.rb', line 28 def self.config @@config ||= Config.new end |
.configure {|self.config| ... } ⇒ Object
Set the configs
33 34 35 |
# File 'lib/prismic_rails.rb', line 33 def self.configure yield self.config end |
.get_cached_ref ⇒ Object
Get the last cached master ref out of the rails cache if prismic is not available
66 67 68 69 70 71 72 73 74 |
# File 'lib/prismic_rails.rb', line 66 def self.get_cached_ref master_ref = get_ref Rails.cache.write('prismic_rails_ref', master_ref) master_ref rescue NoPrismicAPIConnection cached_ref = Rails.cache.fetch('prismic_rails_ref') raise NoPrismicAPIConnection if cached_ref.nil? cached_ref end |
.get_ref ⇒ Object
Get the master ref from the Prismic::API object
77 78 79 |
# File 'lib/prismic_rails.rb', line 77 def self.get_ref api.master_ref.ref end |
.ref ⇒ Object
Get the master ref of prismic account. This is primarily used to establish a caching mechanism.
52 53 54 55 56 57 58 |
# File 'lib/prismic_rails.rb', line 52 def self.ref if caching_enabled? get_cached_ref else get_ref end end |