Class: WCC::Contentful::Middleware::Store::LocaleMiddleware
- Inherits:
-
Object
- Object
- WCC::Contentful::Middleware::Store::LocaleMiddleware
- Defined in:
- lib/wcc/contentful/middleware/store/locale_middleware.rb
Overview
This middleware enforces that all entries returned by the store layer are properly localized. It does this by transforming entries from the store’s “locale=*” format into the specified locale (or default).
Stores keep entries in the “locale=*” format, which is a hash of all locales for each field. This is convenient because the Sync API returns them in this format. However, the Model layer requires localized entries. So, to separate concerns, this middleware handles the transformation.
Constant Summary
Constants included from Store::Interface
Store::Interface::INTERFACE_METHODS
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Attributes included from WCC::Contentful::Middleware::Store
Instance Method Summary collapse
Methods included from EntryLocaleTransformer
#reduce_to_star, #transform_to_locale, #transform_to_star
Methods included from WCC::Contentful::Middleware::Store
#find, #find_all, #find_by, #has_select?, #resolve_includes, #resolve_link, #resolved_link?
Methods included from Store::Interface
#find, #find_all, #find_by, #index, #index?
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/wcc/contentful/middleware/store/locale_middleware.rb', line 15 def configuration @configuration end |
Instance Method Details
#default_locale ⇒ Object
17 18 19 |
# File 'lib/wcc/contentful/middleware/store/locale_middleware.rb', line 17 def default_locale @default_locale ||= configuration&.default_locale&.to_s || 'en-US' end |
#transform(entry, options) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/wcc/contentful/middleware/store/locale_middleware.rb', line 21 def transform(entry, ) locale = [:locale]&.to_s || default_locale if locale == '*' transform_to_star(entry) else transform_to_locale(entry, locale) end end |