Class: Excon::HyperMedia::ResourceObject

Inherits:
Object
  • Object
show all
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

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

#_embeddedObject

_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
  @_embedded ||= Embedded.new(@data['_embedded'])
end

_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

#_propertiesObject



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

Returns:

  • (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