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
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#fields(wanted_locale = default_locale) ⇒ Object
Returns all fields of the asset.
-
#fields_with_locales ⇒ Object
Returns all fields of the asset with locales nested by field.
- #initialize(object = nil) ⇒ Object
- #inspect(info = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
59 60 61 |
# File 'lib/contentful/resource/fields.rb', line 59 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#fields(wanted_locale = default_locale) ⇒ Object
Returns all fields of the asset
11 12 13 14 |
# File 'lib/contentful/resource/fields.rb', line 11 def fields(wanted_locale = default_locale) wanted_locale = wanted_locale.to_s @fields.has_key?(wanted_locale) ? @fields[wanted_locale] : @fields[locale] end |
#fields_with_locales ⇒ Object
Returns all fields of the asset with locales nested by field
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/contentful/resource/fields.rb', line 17 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 |
#initialize(object = nil) ⇒ Object
29 30 31 32 |
# File 'lib/contentful/resource/fields.rb', line 29 def initialize(object = nil, *) super extract_fields_from_object! object if object end |
#inspect(info = nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/contentful/resource/fields.rb', line 34 def inspect(info = nil) if fields.empty? super(info) else super("#{info} @fields=#{fields.inspect}") end end |