Sha256: 1f53b0694eddbbf8fb0db6dc469ead785bc1a002e4037b3e50e8930d0e02f4cb

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

module ContentfulMiddleman
  class Instance
    def initialize(extension)
      @extension = extension
    end

    def entries
      client.entries(options.cda_query)
    end

    def space_name
      @space_name ||= options.space.fetch(:name)
    end

    def content_types_ids_to_mappers
      @content_types_mappers ||= options.content_types.reduce({}) do |acc, (content_type_id, config)|
        content_type_mapper  = config.fetch(:mapper)
        acc[content_type_id] = content_type_mapper
        acc
      end
    end

    def content_types_ids_to_names
      @content_types_names ||= options.content_types.reduce({}) do |acc, (content_type_id, config)|
        content_type_name    = config.fetch(:name)
        acc[content_type_id] = content_type_name
        acc
      end
    end

    private
    def client
      @client ||= Contentful::Client.new(
        access_token:     options.access_token,
        space:            options.space.fetch(:id),
        dynamic_entries:  :auto,
        raise_errors:     true
      )
    end

    def options
      @extension.options
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contentful_middleman-1.0.4 lib/contentful_middleman/instance.rb
contentful_middleman-1.0.3 lib/contentful_middleman/instance.rb
contentful_middleman-1.0.2 lib/contentful_middleman/instance.rb
contentful_middleman-1.0.1 lib/contentful_middleman/instance.rb
contentful_middleman-1.0.0 lib/contentful_middleman/instance.rb