Class: ArtRest::Resources
- Includes:
- Enumerable
- Defined in:
- lib/artrest/resources.rb
Overview
An ArtRest::Resource that doubles as a collection of resources, each such resource being an ArtRest::Resource instance. This is an abstract base class that is not meant to be instantiated.
Example
An ArtRest::Builds instance is a collection of ArtRest::Build instances.
Direct Known Subclasses
Class Method Summary collapse
-
.resources_creator=(block) ⇒ Object
An ArtRest::Resources instance is represented by a parsed JSON hash.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Iterate over all ArtRest::Resource instances contained in this instance.
Methods inherited from Resource
#[], #base_url, check_options, #content, #content!, #content=, create, inherited, #initialize, mime_type=, resource_attributes, #unparsed_content
Constructor Details
This class inherits a constructor from ArtRest::Resource
Class Method Details
.resources_creator=(block) ⇒ Object
An ArtRest::Resources instance is represented by a parsed JSON hash. In order to be able to iterate over the contained ArtRest::Resource instances we need a means of converting that JSON hash into an array of ArtRest::Resource instances of an appropriate subtype. We choose a block
taking the JSON hash and the options
hash and returning an array of ArtRest::Resource instances.
This method assigns that block to this class.
-
Args :
-
block
-> Ablock
taking a parsed JSON hash and anoptions
hash and returning an array of appropriate ArtRest::Resource instances
-
32 33 34 35 36 37 38 |
# File 'lib/artrest/resources.rb', line 32 def resources_creator=(block) self.singleton_class.class_eval do define_method(:resources_creator) do block end end end |
Instance Method Details
#each(&block) ⇒ Object
Iterate over all ArtRest::Resource instances contained in this instance. Yield each such instance to the supplied block
.
-
Args :
-
block
-> Theblock
to yield each contained ArtRest::Resource instance to
-
50 51 52 |
# File 'lib/artrest/resources.rb', line 50 def each &block # :yields: content, options self.class.resources_creator.call(content, ).each &block end |