Class: Vng::Relation
Overview
Provides methods to iterate through collections of Vonigo resources.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(options = {}) {|Hash| ... } ⇒ Relation
constructor
A new instance of Relation.
-
#select(*parts) ⇒ Vng::Relation
Specifies which parts of the resource to fetch when hitting the data API.
-
#where(conditions = {}) ⇒ Vng::Relation
Specifies which items to fetch when hitting the data API.
Constructor Details
#initialize(options = {}) {|Hash| ... } ⇒ Relation
Returns a new instance of Relation.
8 9 10 11 12 |
# File 'lib/vng/relation.rb', line 8 def initialize( = {}, &item_block) @options = {parts: ['objectID', 'isActive'], next_page: 1} @options.merge! @item_block = item_block end |
Instance Method Details
#each ⇒ Object
36 37 38 39 40 41 |
# File 'lib/vng/relation.rb', line 36 def each @last_index = 0 while next_item = find_next yield next_item end end |
#select(*parts) ⇒ Vng::Relation
Specifies which parts of the resource to fetch when hitting the data API.
28 29 30 31 32 33 34 |
# File 'lib/vng/relation.rb', line 28 def select(*parts) if @options[:parts] != parts + ['objectID', 'isActive'] @items = nil @options.merge! parts: (parts + ['objectID', 'isActive']) end self end |
#where(conditions = {}) ⇒ Vng::Relation
Specifies which items to fetch when hitting the data API.
17 18 19 20 21 22 23 |
# File 'lib/vng/relation.rb', line 17 def where(conditions = {}) if @options[:conditions] != conditions @items = [] @options.merge! conditions: conditions end self end |