Module: Contentful::Management::Resource::Fields
Class Method Summary collapse
-
.included(base) ⇒ Object
Create accessors for content type, asset, entry objects.
Instance Method Summary collapse
- #fields(wanted_locale = default_locale) ⇒ Object
- #initialize(object = nil) ⇒ Object
- #inspect(info = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
Create accessors for content type, asset, entry objects.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/contentful/management/resource/fields.rb', line 28 def self.included(base) base.fields_coercions.keys.each { |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 |
Instance Method Details
#fields(wanted_locale = default_locale) ⇒ Object
7 8 9 10 11 |
# File 'lib/contentful/management/resource/fields.rb', line 7 def fields(wanted_locale = default_locale) requested_locale = locale || wanted_locale @fields[requested_locale] = {} unless @fields[requested_locale] @fields[requested_locale] end |
#initialize(object = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/contentful/management/resource/fields.rb', line 13 def initialize(object = nil, *) super @fields = {} extract_fields_from_object! object if object end |
#inspect(info = nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/contentful/management/resource/fields.rb', line 19 def inspect(info = nil) if fields.empty? super(info) else super("#{ info } @fields=#{ fields.inspect }") end end |