Class: Locomotive::Mounter::Writer::Api::ContentEntriesWriter

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/mounter/writer/api/content_entries_writer.rb

Overview

Push content entries to a remote LocomotiveCMS engine.

TODO: They get created or changed only if the :data option has been passed.

Instance Attribute Summary collapse

Attributes inherited from Base

#mounting_point, #runner

Instance Method Summary collapse

Methods inherited from Base

#absolute_path, #data?, #each_locale, #get, #initialize, #path_to_file, #post, #put, #replace_content_assets!, #safe_attributes

Constructor Details

This class inherits a constructor from Locomotive::Mounter::Writer::Api::Base

Instance Attribute Details

#with_relationshipsObject

Returns the value of attribute with_relationships.



13
14
15
# File 'lib/locomotive/mounter/writer/api/content_entries_writer.rb', line 13

def with_relationships
  @with_relationships
end

Instance Method Details

#prepareObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/locomotive/mounter/writer/api/content_entries_writer.rb', line 15

def prepare
  return unless self.data?

  super

  # initialize the list storing all the entries including relationships
  self.with_relationships = []

  # assign an _id to a local content entry if possible
  self.content_types.each do |slug, content_type|
    entries = self.get("content_types/#{slug}/entries", nil, true)

    entries.each do |attributes|
      content_entry = content_type.find_entry(attributes['_slug'])

      if content_entry
        self.apply_response(content_entry, attributes)
      end
    end
  end
end

#writeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/locomotive/mounter/writer/api/content_entries_writer.rb', line 37

def write
  return unless self.data?

  self.each_locale do |locale|
    self.output_locale

    self.content_types.each do |slug, content_type|
      (content_type.entries || []).each do |entry|
        next unless entry.translated_in?(locale)

        if entry.persisted?
          self.update_content_entry(slug, entry)
        else
          self.create_content_entry(slug, entry)
        end

        self.register_relationships(slug, entry)
      end # content entries
    end # content type
  end # locale

  self.persist_content_entries_with_relationships
end