Class: Contentful::Sync
- Inherits:
-
Object
- Object
- Contentful::Sync
- Defined in:
- lib/contentful/sync.rb
Overview
Resource class for Sync.
Instance Attribute Summary collapse
-
#next_sync_url ⇒ Object
readonly
Returns the value of attribute next_sync_url.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
Returns false as long as last sync page has not been reached.
-
#each_item {|Contentful::Entry, Contentful::Asset| ... } ⇒ Object
Directly iterates over all resources that have changed.
-
#each_page {|Contentful::SyncPage| ... } ⇒ Object
Iterates over all pages of the current sync.
-
#first_page ⇒ Contentful::SyncPage
Returns the first sync result page.
- #get(options_or_url) ⇒ Object
-
#initialize(client, options_or_url) ⇒ Sync
constructor
A new instance of Sync.
Constructor Details
#initialize(client, options_or_url) ⇒ Sync
Returns a new instance of Sync.
12 13 14 15 16 |
# File 'lib/contentful/sync.rb', line 12 def initialize(client, ) @client = client @next_sync_url = nil @first_page_options_or_url = end |
Instance Attribute Details
#next_sync_url ⇒ Object (readonly)
Returns the value of attribute next_sync_url.
10 11 12 |
# File 'lib/contentful/sync.rb', line 10 def next_sync_url @next_sync_url end |
Instance Method Details
#completed? ⇒ Boolean
Returns false as long as last sync page has not been reached
43 44 45 46 47 |
# File 'lib/contentful/sync.rb', line 43 def completed? # rubocop:disable Style/DoubleNegation !!next_sync_url # rubocop:enable Style/DoubleNegation end |
#each_item {|Contentful::Entry, Contentful::Asset| ... } ⇒ Object
Directly iterates over all resources that have changed
52 53 54 55 56 |
# File 'lib/contentful/sync.rb', line 52 def each_item(&block) each_page do |page| page.each_item(&block) end end |
#each_page {|Contentful::SyncPage| ... } ⇒ Object
Note:
Please Keep in Mind: Iterating fires a new request for each page
Iterates over all pages of the current sync
23 24 25 26 27 28 29 30 31 |
# File 'lib/contentful/sync.rb', line 23 def each_page page = first_page yield page if block_given? until completed? page = page.next_page yield page if block_given? end end |
#first_page ⇒ Contentful::SyncPage
Returns the first sync result page
36 37 38 |
# File 'lib/contentful/sync.rb', line 36 def first_page get(@first_page_options_or_url) end |
#get(options_or_url) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/contentful/sync.rb', line 59 def get() page = fetch_page() return page if @client.configuration[:raw_mode] link_page_to_sync! page update_sync_state_from! page page end |