Module: Contentful::Management::Resource::FieldAware

Defined in:
lib/contentful/management/resource/field_aware.rb

Overview

Module for creating Fields based off of ContentTypes

Class Method Summary collapse

Class Method Details

.create_fields_for_content_type(entry, method = :instance) ⇒ Object

Creates fields for entry based on it’s ContentType

Parameters:

  • entry (Entry)

    the expected entry to modify



11
12
13
14
15
16
17
18
# File 'lib/contentful/management/resource/field_aware.rb', line 11

def self.create_fields_for_content_type(entry, method = :instance)
  entry.content_type.fields.each do |field|
    accessor_name = Support.snakify(field.id)

    FieldAware.create_getter(entry, accessor_name, field, method)
    FieldAware.create_setter(entry, accessor_name, field, method)
  end
end

.localized_or_default_locale(field, default_locale, locale) ⇒ Boolean

Verifies if field is localized or default locale matches current locale

Parameters:

  • field (Field)

    an entry field

  • default_locale (String)
  • locale (String)

Returns:

  • (Boolean)


68
69
70
# File 'lib/contentful/management/resource/field_aware.rb', line 68

def self.localized_or_default_locale(field, default_locale, locale)
  field.localized || default_locale == locale
end