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
12 13 14 15 16 17 18 19 |
# File 'lib/contentful/fields_resource.rb', line 12 def initialize(item, _configuration, localized = false, includes = [], entries = {}, depth = 0, errors = []) super @configuration[:errors] = errors @localized = localized @fields = hydrate_fields(includes, entries, errors) define_fields_methods! end |
Instance Attribute Details
#localized ⇒ Object (readonly)
Returns the value of attribute localized
9 10 11 |
# File 'lib/contentful/fields_resource.rb', line 9 def localized @localized end |
Instance Method Details
#fields(wanted_locale = nil) ⇒ Hash
Returns all fields of the asset
24 25 26 27 |
# File 'lib/contentful/fields_resource.rb', line 24 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
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/contentful/fields_resource.rb', line 32 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
45 46 47 |
# File 'lib/contentful/fields_resource.rb', line 45 def locales @fields.keys end |