Class: AutotaskApi::EntityCollection
- Inherits:
-
Object
- Object
- AutotaskApi::EntityCollection
- Includes:
- Enumerable
- Defined in:
- lib/autotask_api/entity_collection.rb
Constant Summary collapse
- PAGE_SIZE =
500
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(class_name, entities, condition, client = AutotaskApi.client) ⇒ EntityCollection
constructor
A new instance of EntityCollection.
- #last(&block) ⇒ Object
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
Constructor Details
#initialize(class_name, entities, condition, client = AutotaskApi.client) ⇒ EntityCollection
Returns a new instance of EntityCollection.
11 12 13 14 15 16 |
# File 'lib/autotask_api/entity_collection.rb', line 11 def initialize(class_name, entities, condition, client = AutotaskApi.client) @class_name = class_name @entities = entities @condition = condition @client = client end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
9 10 11 |
# File 'lib/autotask_api/entity_collection.rb', line 9 def class_name @class_name end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/autotask_api/entity_collection.rb', line 9 def client @client end |
#condition ⇒ Object
Returns the value of attribute condition.
7 8 9 |
# File 'lib/autotask_api/entity_collection.rb', line 7 def condition @condition end |
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
9 10 11 |
# File 'lib/autotask_api/entity_collection.rb', line 9 def entities @entities end |
Instance Method Details
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/autotask_api/entity_collection.rb', line 18 def each(&block) entities.each(&block) end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/autotask_api/entity_collection.rb', line 41 def empty? entities.empty? end |
#last(&block) ⇒ Object
22 23 24 |
# File 'lib/autotask_api/entity_collection.rb', line 22 def last(&block) entities.last(&block) end |
#next_page ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/autotask_api/entity_collection.rb', line 30 def next_page new_expression = Expression.new('id', 'GreaterThan', entities.last[:id]) condition.remove_expression_by_field('id') params = condition.expressions.empty? ? new_expression : [condition, new_expression] new_condition = Condition.new(params) class_name.where(new_condition, client) end |
#next_page? ⇒ Boolean
26 27 28 |
# File 'lib/autotask_api/entity_collection.rb', line 26 def next_page? entities.size >= PAGE_SIZE end |