Module: ContentfulModel::Migrations::ContentTypeFactory

Defined in:
lib/contentful_model/migrations/content_type_factory.rb

Overview

Content Type Factory class

Class Method Summary collapse

Class Method Details

.create(name, fields = {}) {|content_type| ... } ⇒ Object

Yields:

  • (content_type)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/contentful_model/migrations/content_type_factory.rb', line 7

def self.create(name, fields = {}, &_block)
  content_type = ContentfulModel::Migrations::ContentType.new(name)

  yield(content_type) if block_given?

  fields.each do |field_name, type|
    content_type.field(field_name, type)
  end

  content_type.save
end

.find(content_type_id) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/contentful_model/migrations/content_type_factory.rb', line 19

def self.find(content_type_id)
  ContentfulModel::Migrations::ContentType.new(
    nil,
    ContentfulModel::Management.new.content_types(
      ContentfulModel.configuration.space,
      ContentfulModel.configuration.environment
    ).find(content_type_id)
  )
end