class ContentfulLite::Entry

Attributes

content_type_id[R]

The id for the content type of this entry

Public Class Methods

field_reader(*attrs, default: nil, localizable: false) click to toggle source

Defines a field existing on the content type. This macro registers the accessor for that field @param attrs [Array<Symbol,String>] The field names @param default [Object, nil] The default value to return if field is not present on API response @param localizable [Boolean] If the field is marked as localizable @example Defines two string localizable localized fields

field_reader :first_name, :last_name, localizable: true

@see github.com/JuulLabs-OSS/contentful_lite#creating-your-model-classes-with-macros

# File lib/contentful_lite/entry.rb, line 34
def self.field_reader(*attrs, default: nil, localizable: false)
  attrs.each do |k|
    define_method(k) do |locale: nil|
      field = fields(locale: localizable ? locale : default_locale)[k.to_s]
      field.nil? ? default : field
    end
  end
end
new(raw) click to toggle source

@param raw [Hash] raw response from Contentful API @api private

Calls superclass method ContentfulLite::CommonData::new
# File lib/contentful_lite/entry.rb, line 12
def initialize(raw)
  super(raw)
  @content_type_id = raw['sys']['contentType']['sys']['id']
  @localized_fields.values.each do |fields|
    fields.transform_values! { |value| build_link(value) }
  end
end

Public Instance Methods

Private Instance Methods