Class: ContentfulMiddleman::Mapper::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries, options) ⇒ Base

Returns a new instance of Base.



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

def initialize(entries, options)
  @entries = entries
  @options = options
  @children = {}
  @created_at_key = using_camel_case? ? :createdAt : :created_at
  @updated_at_key = using_camel_case? ? :updatedAt : :updated_at
  @content_type_key = using_camel_case? ? :contentType : :content_type
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



6
7
8
# File 'lib/contentful_middleman/mappers/base.rb', line 6

def entries
  @entries
end

Instance Method Details

#map(context, entry) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/contentful_middleman/mappers/base.rb', line 17

def map(context, entry)
  @children = {
    :queue => [{ :context => context, :entry => entry }],
    :discovered => [entry.id] }
  while !@children[:queue].first.nil? do
    nxt = @children[:queue].pop
    context = nxt[:context]
    entry = nxt[:entry]
    map_entry_full(entry, context)
  end
end