class Locomotive::Wagon::Generators::ContentType

Public Class Methods

source_root() click to toggle source
# File lib/locomotive/wagon/generators/content_type.rb, line 30
def self.source_root
  File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'content_type')
end

Public Instance Methods

copy_sources() click to toggle source
# File lib/locomotive/wagon/generators/content_type.rb, line 22
def copy_sources
  directory('.', target_path, { recursive: true }, {
    name:   name,
    slug:   slug,
    fields: extract_fields(fields)
  })
end

Protected Instance Methods

extract_fields(fields) click to toggle source
# File lib/locomotive/wagon/generators/content_type.rb, line 40
def extract_fields(fields)
  fields.map do |raw_attributes|
    name, type, label, required, localized, target_content_type_slug  = raw_attributes.split(':')

    OpenStruct.new(
      name:       name,
      label:      label || name.humanize,
      type:       type || 'string',
      required:   %w(true required).include?(required),
      localized:  %w(true localized).include?(localized)
    ).tap do |field|
      if %w(belongs_to has_many many_to_many).include?(type)
        field.class_name = target_content_type_slug

        inverse_of = type == 'belongs_to' ? target_content_type_slug.singularize : target_content_type_slug

        field.inverse_of = inverse_of
      end
    end
  end
end
name() click to toggle source
# File lib/locomotive/wagon/generators/content_type.rb, line 36
def name
  options['name'] || slug.humanize
end