Class: Consyncful::PersistedItem

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

Overview

Takes a mapped item from Contentful and creates/updates/deletes the relevant model in the local database.

Constant Summary collapse

DEFAULT_LOCALE =
'en-NZ'

Instance Method Summary collapse

Constructor Details

#initialize(item, sync_id, stats) ⇒ PersistedItem

Returns a new instance of PersistedItem.



10
11
12
13
14
# File 'lib/consyncful/persisted_item.rb', line 10

def initialize(item, sync_id, stats)
  @item = item
  @sync_id = sync_id
  @stats = stats
end

Instance Method Details

#persistObject



16
17
18
19
20
21
22
23
24
# File 'lib/consyncful/persisted_item.rb', line 16

def persist
  puts Rainbow("syncing: #{@item.id}").yellow

  if @item.deletion? || @item.excluded_by_tag?
    delete_model(@item.id, @stats)
  else
    create_or_update_model(@item, @sync_id, @stats)
  end
end