Module: Contentful::Management::Resource::Fields
Overview
Adds fields logic for [Resource] classes
Class Method Summary collapse
-
.included(base) ⇒ Object
Create accessors for content type, asset, entry objects.
Instance Method Summary collapse
-
#fields(wanted_locale = default_locale) ⇒ Hash
Returns the fields hash for the specified locale.
Class Method Details
.included(base) ⇒ Object
Create accessors for content type, asset, entry objects.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/contentful/management/resource/fields.rb', line 36 def self.included(base) base.fields_coercions.keys.each do |name| accessor_name = Contentful::Management::Support.snakify(name) base.send :define_method, accessor_name do fields[name.to_sym] end base.send :define_method, "#{accessor_name}_with_locales" do fields_for_query[name.to_sym] end base.send :define_method, "#{accessor_name}=" do |value| fields[name.to_sym] = value end base.send :define_method, "#{accessor_name}_with_locales=" do |values| values.each do |locale, value| @fields[locale] = {} unless @fields[locale] @fields[locale][name.to_sym] = value end end end end |
Instance Method Details
#fields(wanted_locale = default_locale) ⇒ Hash
Returns the fields hash for the specified locale
13 14 15 16 17 |
# File 'lib/contentful/management/resource/fields.rb', line 13 def fields(wanted_locale = default_locale) requested_locale = locale || wanted_locale @fields[requested_locale] = {} unless @fields[requested_locale] @fields[requested_locale] end |