Class: ContentfulMiddleman::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful_middleman/instance.rb

Constant Summary collapse

API_PREVIEW_URL =
'preview.contentful.com'

Instance Method Summary collapse

Constructor Details

#initialize(extension) ⇒ Instance

Returns a new instance of Instance.



5
6
7
# File 'lib/contentful_middleman/instance.rb', line 5

def initialize(extension)
  @extension = extension
end

Instance Method Details

#clientObject



41
42
43
# File 'lib/contentful_middleman/instance.rb', line 41

def client
  @client ||= Contentful::Client.new(client_options)
end

#content_types_ids_to_mappersObject



21
22
23
24
25
26
27
# File 'lib/contentful_middleman/instance.rb', line 21

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

#content_types_ids_to_namesObject



29
30
31
32
33
34
35
# File 'lib/contentful_middleman/instance.rb', line 29

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

#entriesObject



9
10
11
12
13
14
15
# File 'lib/contentful_middleman/instance.rb', line 9

def entries
  if options.all_entries
    all_entries(options.cda_query)
  else
    client.entries(options.cda_query)
  end
end

#optionsObject



37
38
39
# File 'lib/contentful_middleman/instance.rb', line 37

def options
  @extension.options
end

#space_nameObject



17
18
19
# File 'lib/contentful_middleman/instance.rb', line 17

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