Class: WCC::Contentful::Configuration
- Inherits:
-
Object
- Object
- WCC::Contentful::Configuration
- Defined in:
- lib/wcc/contentful/configuration.rb
Constant Summary collapse
- ATTRIBUTES =
i[ access_token management_token space default_locale content_delivery override_get_http ].freeze
- CDN_METHODS =
[ :eager_sync, # TODO: :lazy_sync :direct ].freeze
- SYNC_STORES =
{ memory: ->(_config) { WCC::Contentful::Store::MemoryStore.new }, postgres: ->(_config) { require_relative 'store/postgres_store' WCC::Contentful::Store::PostgresStore.new(ENV['POSTGRES_CONNECTION']) } }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#management_client ⇒ Object
readonly
Returns the value of attribute management_client.
-
#override_get_http ⇒ Object
writeonly
A proc which overrides the “get_http” function in Contentful::Client.
Instance Method Summary collapse
- #configure_contentful ⇒ Object
- #content_delivery=(symbol) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #sync_store ⇒ Object
- #sync_store=(symbol) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
54 55 56 57 58 59 60 61 |
# File 'lib/wcc/contentful/configuration.rb', line 54 def initialize @access_token = '' @management_token = '' @space = '' @default_locale = nil @content_delivery = :direct @sync_store = :memory end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
63 64 65 |
# File 'lib/wcc/contentful/configuration.rb', line 63 def client @client end |
#management_client ⇒ Object (readonly)
Returns the value of attribute management_client.
64 65 66 |
# File 'lib/wcc/contentful/configuration.rb', line 64 def management_client @management_client end |
#override_get_http=(value) ⇒ Object (writeonly)
A proc which overrides the “get_http” function in Contentful::Client. All interaction with Contentful will go through this function. Should be a lambda like: ->(url, query, headers = {}, proxy = {}) { … }
52 53 54 |
# File 'lib/wcc/contentful/configuration.rb', line 52 def override_get_http=(value) @override_get_http = value end |
Instance Method Details
#configure_contentful ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wcc/contentful/configuration.rb', line 66 def configure_contentful @client = nil @management_client = nil if defined?(::ContentfulModel) ContentfulModel.configure do |config| config.access_token = access_token config.management_token = management_token if management_token.present? config.space = space config.default_locale = default_locale || 'en-US' end end require_relative 'client_ext' if defined?(::Contentful) @client = WCC::Contentful::SimpleClient::Cdn.new( access_token: access_token, space: space, default_locale: default_locale ) return unless management_token.present? @management_client = WCC::Contentful::SimpleClient::Management.new( management_token: management_token, space: space, default_locale: default_locale ) end |
#content_delivery=(symbol) ⇒ Object
30 31 32 33 |
# File 'lib/wcc/contentful/configuration.rb', line 30 def content_delivery=(symbol) raise ArgumentError, "Please set one of #{CDN_METHODS}" unless CDN_METHODS.include?(symbol) @content_delivery = symbol end |
#sync_store ⇒ Object
44 45 46 47 |
# File 'lib/wcc/contentful/configuration.rb', line 44 def sync_store @sync_store = SYNC_STORES[@sync_store].call(self) if @sync_store.is_a? Symbol @sync_store ||= Store::MemoryStore.new end |
#sync_store=(symbol) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/wcc/contentful/configuration.rb', line 35 def sync_store=(symbol) if symbol.is_a? Symbol unless SYNC_STORES.keys.include?(symbol) raise ArgumentError, "Please use one of #{SYNC_STORES.keys}" end end @sync_store = symbol end |