Class: ApiNavigator::Resources::CollectionResource
- Inherits:
-
ApiNavigator::Resource
- Object
- ApiNavigator::Resource
- ApiNavigator::Resources::CollectionResource
- Defined in:
- lib/api_navigator/resources/collection_resource.rb
Instance Attribute Summary collapse
-
#_collection ⇒ Object
readonly
Returns the embedded resource of the Resource as a ResourceCollection.
Attributes inherited from ApiNavigator::Resource
Instance Method Summary collapse
-
#initialize(representation, entry_point, response = nil) ⇒ CollectionResource
constructor
Initializes a Resource.
-
#method_missing(method, *args, &block) ⇒ Object
private
Delegate the method to various elements of the resource.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
private
Accessory method to allow the resource respond to methods that will hit method_missing.
Methods inherited from ApiNavigator::Resource
#[], #_self_link, #_status, #_success?, #fetch, from_representation, #inspect, #validate
Constructor Details
#initialize(representation, entry_point, response = nil) ⇒ CollectionResource
Initializes a Resource.
13 14 15 16 17 18 |
# File 'lib/api_navigator/resources/collection_resource.rb', line 13 def initialize(representation, entry_point, response = nil) super collection_data = representation.fetch('data') @_collection = collection_data.map do |resource| Resources::MemberResource.from_representation(resource, entry_point) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegate the method to various elements of the resource.
This allows ‘api.posts` instead of `api.links.posts.resource` as well as api.posts(id: 1) assuming posts is a link.
24 25 26 27 28 29 30 |
# File 'lib/api_navigator/resources/collection_resource.rb', line 24 def method_missing(method, *args, &block) begin @_collection.send(method, *args, &block) rescue NoMethodError super end end |
Instance Attribute Details
#_collection ⇒ Object (readonly)
Returns the embedded resource of the Resource as a ResourceCollection.
7 8 9 |
# File 'lib/api_navigator/resources/collection_resource.rb', line 7 def _collection @_collection end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Accessory method to allow the resource respond to methods that will hit method_missing.
34 35 36 37 |
# File 'lib/api_navigator/resources/collection_resource.rb', line 34 def respond_to_missing?(method, include_private = false) @_collection.respond_to?(method, include_private) || super end |