Class: Excon::HyperMedia::ResourceObject
- Inherits:
-
Object
- Object
- Excon::HyperMedia::ResourceObject
- Defined in:
- lib/excon/hypermedia/resource_object.rb,
lib/excon/hypermedia/resource_object/links.rb,
lib/excon/hypermedia/resource_object/embedded.rb,
lib/excon/hypermedia/resource_object/properties.rb
Overview
ResourceObject
Represents a resource.
Defined Under Namespace
Classes: Embedded, Links, Properties
Constant Summary collapse
- RESERVED_PROPERTIES =
%w[_links _embedded].freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#_embedded ⇒ Object
_embedded.
-
#_links ⇒ Object
_links.
- #_properties ⇒ Object
-
#initialize(data) ⇒ ResourceObject
constructor
A new instance of ResourceObject.
- #method_missing(method_name, *_) ⇒ Object
- #respond_to_missing?(method_name, _ = false) ⇒ Boolean
Constructor Details
#initialize(data) ⇒ ResourceObject
Returns a new instance of ResourceObject.
16 17 18 |
# File 'lib/excon/hypermedia/resource_object.rb', line 16 def initialize(data) @data = data end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_) ⇒ Object
60 61 62 |
# File 'lib/excon/hypermedia/resource_object.rb', line 60 def method_missing(method_name, *_) _properties.respond_to?(method_name) ? _properties.send(method_name) : super end |
Instance Method Details
#[](key) ⇒ Object
56 57 58 |
# File 'lib/excon/hypermedia/resource_object.rb', line 56 def [](key) _properties[key] end |
#_embedded ⇒ Object
_embedded
The reserved “_embedded” property is OPTIONAL
It is an object whose property names are link relation types (as defined by [RFC5988]) and values are either a Resource Object or an array of Resource Objects.
Embedded Resources MAY be a full, partial, or inconsistent version of the representation served from the target URI.
52 53 54 |
# File 'lib/excon/hypermedia/resource_object.rb', line 52 def ||= Embedded.new(@data['_embedded']) end |
#_links ⇒ Object
_links
The reserved “_links” property is OPTIONAL.
It is an object whose property names are link relation types (as defined by [RFC5988]) and values are either a Link Object or an array of Link Objects. The subject resource of these links is the Resource Object of which the containing “_links” object is a property.
35 36 37 |
# File 'lib/excon/hypermedia/resource_object.rb', line 35 def _links @_links ||= Links.new(@data['_links']) end |
#_properties ⇒ Object
20 21 22 |
# File 'lib/excon/hypermedia/resource_object.rb', line 20 def _properties @_properties ||= Properties.new(@data.reject { |k, _| RESERVED_PROPERTIES.include?(k) }) end |
#respond_to_missing?(method_name, _ = false) ⇒ Boolean
64 65 66 |
# File 'lib/excon/hypermedia/resource_object.rb', line 64 def respond_to_missing?(method_name, _ = false) _properties.respond_to?(method_name) || super end |