class ContentfulMiddleman::Core

Attributes

middleman_app[R]

Public Class Methods

new(app, options_hash = {}, &block) click to toggle source
Calls superclass method
# File lib/contentful_middleman/core.rb, line 76
def initialize(app, options_hash = {}, &block)
  super
  @middleman_app = app

  this = self # Hack due to context change
  app.before_server do
    this.webhook_options
  end
end

Public Instance Methods

after_configuration() click to toggle source

Middleman hooks

# File lib/contentful_middleman/core.rb, line 89
def after_configuration
  massage_options

  ContentfulMiddleman.instances << (ContentfulMiddleman::Instance.new self)
end
webhook_options() click to toggle source
# File lib/contentful_middleman/core.rb, line 95
def webhook_options
  ::ContentfulMiddleman::WebhookHandler.start(options) if options.rebuild_on_webhook
end

Private Instance Methods

massage_content_types_options() click to toggle source
# File lib/contentful_middleman/core.rb, line 113
def massage_content_types_options
  content_types_options     = options.content_types
  new_content_types_options = content_types_options.each_with_object({}) do |(content_type_name, value), options|
    if value.is_a? Hash
      mapper = value.fetch(:mapper)
      id     = value.fetch(:id)
    else
      mapper = Mapper::Base
      id     = value
    end

    options[id] = {name: content_type_name, mapper: mapper}
  end

  options.content_types = new_content_types_options
end
massage_options() click to toggle source
# File lib/contentful_middleman/core.rb, line 100
def massage_options
  massage_space_options
  massage_content_types_options
end
massage_space_options() click to toggle source
# File lib/contentful_middleman/core.rb, line 105
def massage_space_options
  space_option          = options.space
  space_name            = space_option.keys.first
  space_id              = space_option.fetch(space_name)

  options.space = { name: space_name, id: space_id }
end