Class: Locomotive::Mounter::Writer::Api::ContentTypesWriter

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

Overview

Push content types to a remote LocomotiveCMS engine.

In a first time, create the content types without any relationships fields. Then, add the relationships one by one.

If the :force option is passed, the remote fields not defined in the mounter version of the content type will be destroyed when pushed. The options of a select field will be pushed as well, otherwise they won’t unless if it is a brand new content type.

Instance Attribute Summary

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 Method Details

#prepareObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/locomotive/mounter/writer/api/content_types_writer.rb', line 18

def prepare
  super

  # assign an _id to a local content type if possible
  self.get(:content_types, nil, true).each do |attributes|
    content_type = self.content_types[attributes['slug']]

    self.apply_response(content_type, attributes)
  end
end

#writeObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/locomotive/mounter/writer/api/content_types_writer.rb', line 29

def write
  done = {}

  # first new content types
  self.not_persisted.each do |content_type|
    self.create_content_type(content_type)

    done[content_type.slug] = content_type.with_relationships? ? :todo : :done
  end

  # then update the others
  self.content_types.values.each do |content_type|
    next unless done[content_type.slug].nil?

    self.update_content_type(content_type)
  end

  # finally, update the newly created embedding a relationship field
  done.each do |slug, status|
    next if status == :done

    content_type = self.content_types[slug]

    self.update_content_type(content_type)
  end
end