Class: Contentful::FieldsResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Contentful::FieldsResource
- Defined in:
- lib/contentful/fields_resource.rb
Overview
Base definition of a Contentful Resource containing Field properties
Instance Attribute Summary collapse
-
#localized ⇒ Object
readonly
Returns the value of attribute localized.
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#fields(wanted_locale = nil) ⇒ Hash
Returns all fields of the asset.
-
#fields_with_locales ⇒ Hash
Returns all fields of the asset with locales nested by field.
-
#initialize(item, _configuration, localized = false, includes = [], entries = {}, depth = 0, errors = []) ⇒ FieldsResource
constructor
rubocop:disable Metrics/ParameterLists.
-
#locales ⇒ Object
Provides a list of the available locales for a Resource.
Methods inherited from BaseResource
Constructor Details
#initialize(item, _configuration, localized = false, includes = [], entries = {}, depth = 0, errors = []) ⇒ FieldsResource
rubocop:disable Metrics/ParameterLists
10 11 12 13 14 15 16 |
# File 'lib/contentful/fields_resource.rb', line 10 def initialize(item, _configuration, localized = false, includes = [], entries = {}, depth = 0, errors = []) super @localized = localized @fields = hydrate_fields(includes, entries, errors) define_fields_methods! end |
Instance Attribute Details
#localized ⇒ Object (readonly)
Returns the value of attribute localized.
7 8 9 |
# File 'lib/contentful/fields_resource.rb', line 7 def localized @localized end |
Instance Method Details
#fields(wanted_locale = nil) ⇒ Hash
Returns all fields of the asset
21 22 23 24 |
# File 'lib/contentful/fields_resource.rb', line 21 def fields(wanted_locale = nil) wanted_locale = internal_resource_locale if wanted_locale.nil? @fields.fetch(wanted_locale.to_s, {}) end |
#fields_with_locales ⇒ Hash
Returns all fields of the asset with locales nested by field
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/contentful/fields_resource.rb', line 29 def fields_with_locales remapped_fields = {} locales.each do |locale| fields(locale).each do |name, value| remapped_fields[name] ||= {} remapped_fields[name][locale.to_sym] = value end end remapped_fields end |
#locales ⇒ Object
Provides a list of the available locales for a Resource
42 43 44 |
# File 'lib/contentful/fields_resource.rb', line 42 def locales @fields.keys end |