Module: Contentful::Resource::Fields

Included in:
Entry
Defined in:
lib/contentful/resource/fields.rb

Overview

Include this module into your Resource class to enable it to deal with entry fields (but not asset fields)

It depends on system properties being available

Instance Method Summary collapse

Instance Method Details

#fields(wanted_locale = default_locale) ⇒ Hash

Returns all fields of the asset

Returns:

  • (Hash)

    fields for Resource on selected locale



13
14
15
16
# File 'lib/contentful/resource/fields.rb', line 13

def fields(wanted_locale = default_locale)
  wanted_locale = wanted_locale.to_s
  @fields.key?(wanted_locale) ? @fields[wanted_locale] : @fields[locale]
end

#fields_with_localesHash

Returns all fields of the asset with locales nested by field

Returns:

  • (Hash)

    fields for Resource grouped by field name



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/contentful/resource/fields.rb', line 21

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