Module: Excon::HyperMedia::Collection

Includes:
Enumerable
Included in:
LinkObject, ResourceObject::Embedded, ResourceObject::Links, ResourceObject::Properties
Defined in:
lib/excon/hypermedia/helpers/collection.rb

Overview

Collection

Given a ‘Hash`, provides dot-notation properties and other helper methods.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_) ⇒ Object (private)

method_missing

Collections can be accessed using both the “dot notation” and the hash notation:

collection.hello_world
collection['hello_world']

The second notation returns ‘nil` on missing keys, the first should do as well.



48
49
50
# File 'lib/excon/hypermedia/helpers/collection.rb', line 48

def method_missing(_) # rubocop:disable Style/MethodMissing
  nil
end

Instance Method Details

#[](key) ⇒ Object



31
32
33
# File 'lib/excon/hypermedia/helpers/collection.rb', line 31

def [](key)
  to_property(key)
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/excon/hypermedia/helpers/collection.rb', line 19

def each(&block)
  collection.each(&block)
end

#initialize(collection = {}) ⇒ Object



14
15
16
17
# File 'lib/excon/hypermedia/helpers/collection.rb', line 14

def initialize(collection = {})
  @collection ||= collection.to_h
  to_properties
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/excon/hypermedia/helpers/collection.rb', line 27

def key?(key)
  collection.key?(key.to_s)
end

#keysObject



23
24
25
# File 'lib/excon/hypermedia/helpers/collection.rb', line 23

def keys
  @collection.keys
end