Class: Consyncful::ItemMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/consyncful/item_mapper.rb

Overview

Responsible for mapping an update received from Contentful’s syncronisation API into useful fields for Consyncful::PersistedItem to store in the database.

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ ItemMapper

Returns a new instance of ItemMapper.



8
9
10
# File 'lib/consyncful/item_mapper.rb', line 8

def initialize(item)
  @item = item
end

Instance Method Details

#deletion?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/consyncful/item_mapper.rb', line 12

def deletion?
  @item.is_a?(Contentful::DeletedEntry) || @item.is_a?(Contentful::DeletedAsset)
end

#excluded_by_tag?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/consyncful/item_mapper.rb', line 16

def excluded_by_tag?
  return (Consyncful.configuration. & item_tag_ids).empty?      if Consyncful.configuration..any?
  return (Consyncful.configuration. & item_tag_ids).any? if Consyncful.configuration..any?

  false
end

#idObject



30
31
32
# File 'lib/consyncful/item_mapper.rb', line 30

def id
  @item.id
end

#mapped_fields(default_locale) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/consyncful/item_mapper.rb', line 34

def mapped_fields(default_locale)
  fields = generic_fields

  fields.merge!(localized_fields(default_locale))
  fields.merge!(localized_asset_fields(default_locale)) if type == 'asset'
  fields.merge!(contentful_timestamps) if Consyncful.configuration.preserve_contentful_timestamps

  fields
end

#typeObject



23
24
25
26
27
28
# File 'lib/consyncful/item_mapper.rb', line 23

def type
  case @item.type
  when 'Entry' then @item.content_type.id
  when 'Asset' then 'asset'
  end
end