class WCC::Contentful::Services
Public Class Methods
# File lib/wcc/contentful/services.rb, line 6 def instance @singleton__instance__ ||= new # rubocop:disable Naming/MemoizedInstanceVariableName end
# File lib/wcc/contentful/services.rb, line 15 def initialize(configuration = nil) @configuration = configuration end
Public Instance Methods
Gets a {WCC::Contentful::SimpleClient::Cdn CDN Client} which provides methods for getting and paging raw JSON data from the Contentful
CDN.
@api Client
# File lib/wcc/contentful/services.rb, line 61 def client @client ||= ensure_configured do |config| WCC::Contentful::SimpleClient::Cdn.new( **config.connection_options, access_token: config.access_token, space: config.space, default_locale: config.default_locale, connection: config.connection, environment: config.environment ) end end
# File lib/wcc/contentful/services.rb, line 11 def configuration @configuration ||= WCC::Contentful.configuration end
Gets the configured instrumentation adapter, defaulting to ActiveSupport::Notifications
# File lib/wcc/contentful/services.rb, line 134 def instrumentation return @instrumentation if @instrumentation return ActiveSupport::Notifications if WCC::Contentful.configuration.nil? @instrumentation ||= WCC::Contentful.configuration.instrumentation_adapter || ActiveSupport::Notifications end
Gets a {WCC::Contentful::SimpleClient::Management Management Client} which provides methods for updating data via the Contentful
Management API
@api Client
# File lib/wcc/contentful/services.rb, line 99 def management_client @management_client ||= ensure_configured do |config| if config.management_token.present? WCC::Contentful::SimpleClient::Management.new( **config.connection_options, management_token: config.management_token, space: config.space, default_locale: config.default_locale, connection: config.connection, environment: config.environment ) end end end
Gets a {WCC::Contentful::SimpleClient::Cdn CDN Client} which provides methods for getting and paging raw JSON data from the Contentful
Preview API.
@api Client
# File lib/wcc/contentful/services.rb, line 79 def preview_client @preview_client ||= ensure_configured do |config| if config.preview_token.present? WCC::Contentful::SimpleClient::Preview.new( **config.connection_options, preview_token: config.preview_token, space: config.space, default_locale: config.default_locale, connection: config.connection, environment: config.environment ) end end end
An instance of {WCC::Contentful::Store::CDNAdapter} which connects to the Contentful
Preview API to return preview content.
@api Store
# File lib/wcc/contentful/services.rb, line 46 def preview_store @preview_store ||= ensure_configured do |config| WCC::Contentful::Store::Factory.new( config, :direct, :preview ).build(self) end end
Gets the data-store which executes the queries run against the dynamic models in the WCC::Contentful::Model
namespace. This is one of the following based on the configured store method:
- :direct
-
an instance of {WCC::Contentful::Store::CDNAdapter} with a {WCC::Contentful::SimpleClient::Cdn CDN Client} to access the CDN.
- :lazy_sync
-
an instance of {WCC::Contentful::Middleware::Store::CachingMiddleware} with the configured ActiveSupport::Cache implementation around a {WCC::Contentful::Store::CDNAdapter} for when data cannot be found in the cache.
- :eager_sync
-
an instance of the configured
Store
type, defined by {WCC::Contentful::Configuration#sync_store}
@api Store
# File lib/wcc/contentful/services.rb, line 35 def store @store ||= ensure_configured do |config| config.store.build(self) end end
Gets the configured WCC::Contentful::SyncEngine
which is responsible for updating the currently configured store. The application must periodically call next on this instance. Alternately, the application can mount the WCC::Contentful::Engine
, which will call next anytime a webhook is received.
This returns `nil` if the currently configured store does not respond to sync events.
# File lib/wcc/contentful/services.rb, line 122 def sync_engine @sync_engine ||= if store.index? SyncEngine.new( store: store, client: client, key: 'sync:token' ) end end
Private Instance Methods
# File lib/wcc/contentful/services.rb, line 145 def ensure_configured raise StandardError, 'WCC::Contentful has not yet been configured!' if configuration.nil? yield configuration end