Class: Contentful::Sync
- Inherits:
-
Object
- Object
- Contentful::Sync
- Defined in:
- lib/contentful/sync.rb
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(&block) ⇒ Object
Directly iterates over all resources that have changed.
-
#each_page(&block) ⇒ Object
Iterates over all pages of the current sync Please Keep in Mind: Iterating fires a new request for each page.
-
#first_page ⇒ Object
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.
10 11 12 13 14 |
# File 'lib/contentful/sync.rb', line 10 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.
8 9 10 |
# File 'lib/contentful/sync.rb', line 8 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
34 35 36 |
# File 'lib/contentful/sync.rb', line 34 def completed? !!next_sync_url end |
#each_item(&block) ⇒ Object
Directly iterates over all resources that have changed
39 40 41 42 43 44 45 |
# File 'lib/contentful/sync.rb', line 39 def each_item(&block) each_page do |page| page.each_item do |item| block.call item end end end |
#each_page(&block) ⇒ Object
Iterates over all pages of the current sync Please Keep in Mind: Iterating fires a new request for each page
18 19 20 21 22 23 24 25 26 |
# File 'lib/contentful/sync.rb', line 18 def each_page(&block) page = first_page block.call(page) until completed? page = page.next_page block.call(page) end end |
#first_page ⇒ Object
Returns the first sync result page
29 30 31 |
# File 'lib/contentful/sync.rb', line 29 def first_page get(@first_page_options_or_url) end |