Class: ContentfulLite::Entry
- Inherits:
-
Object
- Object
- ContentfulLite::Entry
- Includes:
- CommonData, EntryMapping, Validations::Entry
- Defined in:
- lib/contentful_lite/entry.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content_type_id ⇒ Object
readonly
The id for the content type of this entry.
Attributes included from CommonData
#created_at, #default_locale, #environment_id, #id, #locales, #localized_fields, #retrieved_at, #revision, #space_id, #sys, #updated_at
Class Method Summary collapse
-
.field_reader(*attrs, default: nil, localizable: false) ⇒ Object
Defines a field existing on the content type.
Instance Method Summary collapse
-
#contentful_link ⇒ String
Gets the URL to view/edit the entry on Contentful webapp.
-
#initialize(raw) ⇒ Entry
constructor
private
A new instance of Entry.
Methods included from Validations::Entry
#errors_for_all_locales, #valid_for_all_locales?, validates_included_asset, validates_included_entry
Methods included from CommonData
#as_json, #fields, #locale, #locale=, #to_link, #with_locale
Constructor Details
#initialize(raw) ⇒ Entry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Entry.
12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#content_type_id ⇒ Object (readonly)
The id for the content type of this entry
8 9 10 |
# File 'lib/contentful_lite/entry.rb', line 8 def content_type_id @content_type_id end |
Class Method Details
.field_reader(*attrs, default: nil, localizable: false) ⇒ Object
Defines a field existing on the content type. This macro registers the accessor for that field
34 35 36 37 38 39 40 41 |
# 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 |
Instance Method Details
#contentful_link ⇒ String
Gets the URL to view/edit the entry on Contentful webapp
22 23 24 |
# File 'lib/contentful_lite/entry.rb', line 22 def contentful_link "https://app.contentful.com/spaces/#{space_id}/entries/#{id}" end |