module PrismicRails

Public Class Methods

api() click to toggle source

Returns the Prismic::API Object or nil if prismic.io is down

# 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?() click to toggle source

returns if the caching is enabled

# File lib/prismic_rails.rb, line 61
def self.caching_enabled?
  PrismicRails.config.caching
end
config() click to toggle source

Initalize the Config class

# File lib/prismic_rails.rb, line 28
def self.config
  @@config ||= Config.new
end
configure() { |config| ... } click to toggle source

Set the configs

# File lib/prismic_rails.rb, line 33
def self.configure
  yield self.config
end
get_cached_ref() click to toggle source

Get the last cached master ref out of the rails cache if prismic is not available

# 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() click to toggle source

Get the master ref from the Prismic::API object

# File lib/prismic_rails.rb, line 77
def self.get_ref
  api.master_ref.ref
end
ref() click to toggle source

Get the master ref of prismic account. This is primarily used to establish a caching mechanism.

# File lib/prismic_rails.rb, line 52
def self.ref
  if caching_enabled?
    get_cached_ref
  else
    get_ref
  end
end