lib/wcc/contentful/configuration.rb in wcc-contentful-1.3.2 vs lib/wcc/contentful/configuration.rb in wcc-contentful-1.4.0.rc1
- old
+ new
@@ -6,10 +6,11 @@
access_token
app_url
connection
connection_options
default_locale
+ locale_fallbacks
environment
instrumentation_adapter
logger
management_token
preview_token
@@ -38,10 +39,15 @@
attr_accessor :management_token
# Sets the Environment ID. Leave blank to use master.
attr_accessor :environment
# Sets the default locale. Defaults to 'en-US'.
attr_accessor :default_locale
+ # Sets up locale fallbacks. This is a Ruby hash which maps locale codes to fallback locale codes.
+ # Defaults are loaded from contentful-schema.json but can be overridden here.
+ # If data is missing for one locale, we will use data in the "fallback locale".
+ # See https://www.contentful.com/developers/docs/tutorials/general/setting-locales/#custom-fallback-locales
+ attr_accessor :locale_fallbacks
# Sets the Content Preview API access token. Only required if you use the
# preview flag.
attr_accessor :preview_token
# Sets an optional basic auth username that will be validated by the webhook controller.
# You must ensure the configured webhook sets the "HTTP Basic Auth username"
@@ -104,15 +110,15 @@
#
# [:custom] `config.store :custom, do ... end`
# The block is executed in the context of a WCC::Contentful::Store::Factory.
# this can be used to apply middleware, etc.
def store(*params, &block)
- type, *params = params
- if type
+ preset, *params = params
+ if preset
@store_factory = WCC::Contentful::Store::Factory.new(
self,
- type,
+ preset,
params
)
end
@store_factory.instance_exec(&block) if block_given?
@@ -197,11 +203,12 @@
management_api_url: 'https://api.contentful.com'
}
@management_token = ENV.fetch('CONTENTFUL_MANAGEMENT_TOKEN', nil)
@preview_token = ENV.fetch('CONTENTFUL_PREVIEW_TOKEN', nil)
@space = ENV.fetch('CONTENTFUL_SPACE_ID', nil)
- @default_locale = nil
+ @default_locale = 'en-US'
+ @locale_fallbacks = {}
@middleware = []
@update_schema_file = :if_possible
@schema_file = 'db/contentful-schema.json'
@webhook_jobs = []
@store_factory = WCC::Contentful::Store::Factory.new(self, :direct)
@@ -240,10 +247,10 @@
attr_reader(*ATTRIBUTES)
def initialize(configuration)
ATTRIBUTES.each do |att|
val = configuration.public_send(att)
- val.freeze if val.is_a?(Hash) || val.is_a?(Array)
+ val = val.dup.freeze if val.is_a?(Hash) || val.is_a?(Array)
instance_variable_set("@#{att}", val)
end
end
# Returns true if the currently configured environment is pointing at `master`.