lib/wcc/contentful/store/factory.rb in wcc-contentful-1.3.2 vs lib/wcc/contentful/store/factory.rb in wcc-contentful-1.4.0.rc1
- old
+ new
@@ -3,10 +3,11 @@
require_relative 'base'
require_relative 'memory_store'
require_relative 'cdn_adapter'
require_relative '../middleware/store'
require_relative '../middleware/store/caching_middleware'
+require_relative '../middleware/store/locale_middleware'
module WCC::Contentful::Store
# This factory presents a DSL for configuring the store stack. The store stack
# sits in between the Model layer and the datastore, which can be Contentful
# or something else like Postgres.
@@ -44,18 +45,22 @@
def use(middleware, *middleware_params, &block)
configure_proc = block_given? ? Proc.new(&block) : nil
self.middleware << [middleware, middleware_params, configure_proc]
end
+ # Replaces a middleware in the chain. The middleware to replace is selected
+ # by matching the class.
def replace(middleware, *middleware_params, &block)
idx = self.middleware.find_index { |m| m[0] == middleware }
raise ArgumentError, "Middleware #{middleware} not present" if idx.nil?
configure_proc = block_given? ? Proc.new(&block) : nil
self.middleware[idx] = [middleware, middleware_params, configure_proc]
end
+ # Removes a middleware from the chain, finding it by matching the class
+ # constant.
def unuse(middleware)
idx = self.middleware.find_index { |m| m[0] == middleware }
return if idx.nil?
self.middleware.delete_at idx
@@ -172,10 +177,12 @@
class << self
# The middleware that by default lives at the top of the middleware stack.
def default_middleware
[
- [WCC::Contentful::Store::InstrumentationMiddleware]
+ [WCC::Contentful::Store::InstrumentationMiddleware],
+ # Stores do not guarantee that the entry is resolved to the locale
+ [WCC::Contentful::Middleware::Store::LocaleMiddleware]
].freeze
end
end
end
end