Class: Helium::Collection
- Inherits:
-
Object
- Object
- Helium::Collection
- Includes:
- Enumerable
- Defined in:
- lib/helium/collection.rb
Instance Attribute Summary collapse
-
#filter_criteria ⇒ Object
readonly
Returns the value of attribute filter_criteria.
Instance Method Summary collapse
-
#+(other) ⇒ Object
TODO: could support something like label.sensors << new_sensor see Label#add_sensors for where it would be applied.
- #-(other) ⇒ Object
-
#==(other) ⇒ Object
Collections are considered equal if they contain the same resources as determined by the resources' ids.
- #[](index) ⇒ Object
-
#all ⇒ Helium::Collection
Returns all resources.
-
#collection ⇒ Resource
Returns an array of the Resources belonging to the Collection.
- #each ⇒ Object
-
#initialize(opts) ⇒ Collection
constructor
A new instance of Collection.
- #inspect ⇒ Object
-
#last ⇒ Object
NOTE: if we implement pagination, we'll need to rethink this.
- #to_json(*options) ⇒ Object
-
#where(criteria) ⇒ Collection
Uses metadata filtering (https://docs.helium.com/api/v1/metadata/index.html#filtering) to search for a collection of resources matching the search parameters.
Constructor Details
#initialize(opts) ⇒ Collection
Returns a new instance of Collection
7 8 9 10 11 12 13 |
# File 'lib/helium/collection.rb', line 7 def initialize(opts) @client = opts.fetch(:client) @klass = opts.fetch(:klass) @belongs_to = opts.fetch(:belongs_to, nil) @filter_criteria = {} end |
Instance Attribute Details
#filter_criteria ⇒ Object (readonly)
Returns the value of attribute filter_criteria
5 6 7 |
# File 'lib/helium/collection.rb', line 5 def filter_criteria @filter_criteria end |
Instance Method Details
#+(other) ⇒ Object
TODO: could support something like label.sensors << new_sensor see Label#add_sensors for where it would be applied
60 61 62 |
# File 'lib/helium/collection.rb', line 60 def +(other) collection + other end |
#-(other) ⇒ Object
64 65 66 |
# File 'lib/helium/collection.rb', line 64 def -(other) collection - other end |
#==(other) ⇒ Object
Collections are considered equal if they contain the same resources as determined by the resources' ids
74 75 76 |
# File 'lib/helium/collection.rb', line 74 def ==(other) self.map(&:id).sort == other.map(&:id).sort end |
#[](index) ⇒ Object
68 69 70 |
# File 'lib/helium/collection.rb', line 68 def [](index) collection[index] end |
#all ⇒ Helium::Collection
Returns all resources
18 19 20 21 |
# File 'lib/helium/collection.rb', line 18 def all @filter_criteria = {} self end |
#collection ⇒ Resource
Returns an array of the Resources belonging to the Collection
42 43 44 |
# File 'lib/helium/collection.rb', line 42 def collection fetch_collection end |
#each ⇒ Object
46 47 48 |
# File 'lib/helium/collection.rb', line 46 def each collection.each{ |element| yield element } end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/helium/collection.rb', line 50 def inspect collection end |
#last ⇒ Object
NOTE: if we implement pagination, we'll need to rethink this
79 80 81 |
# File 'lib/helium/collection.rb', line 79 def last collection.last end |
#to_json(*options) ⇒ Object
54 55 56 |
# File 'lib/helium/collection.rb', line 54 def to_json(*) collection.to_json(*) end |
#where(criteria) ⇒ Collection
Uses metadata filtering (https://docs.helium.com/api/v1/metadata/index.html#filtering) to search for a collection of resources matching the search parameters
35 36 37 38 |
# File 'lib/helium/collection.rb', line 35 def where(criteria) add_filter_criteria(criteria) self end |