Class: PactBroker::Client::Hal::Links
- Inherits:
-
Object
- Object
- PactBroker::Client::Hal::Links
- Defined in:
- lib/pact_broker/client/hal/links.rb
Instance Method Summary collapse
- #find(name) ⇒ Object
- #find!(name, not_found_message = nil) ⇒ Object
-
#initialize(href, key, links) ⇒ Links
constructor
A new instance of Links.
- #names ⇒ Object
- #select(name) ⇒ Object
- #select!(name, not_found_message = nil) ⇒ Object
Constructor Details
#initialize(href, key, links) ⇒ Links
Returns a new instance of Links.
8 9 10 11 12 |
# File 'lib/pact_broker/client/hal/links.rb', line 8 def initialize(href, key, links) @href = href @key = key @links = links end |
Instance Method Details
#find(name) ⇒ Object
29 30 31 |
# File 'lib/pact_broker/client/hal/links.rb', line 29 def find(name) links.find{ | link | link.name == name } end |
#find!(name, not_found_message = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pact_broker/client/hal/links.rb', line 18 def find!(name, = nil) link = find(name) if link link else = || "Could not find relation '#{key}' with name '#{name}' in resource at #{href}." = names.any? ? names.join(", ") : "<none found>" raise RelationNotFoundError.new(.chomp(".") + ". Available options: #{}") end end |
#names ⇒ Object
14 15 16 |
# File 'lib/pact_broker/client/hal/links.rb', line 14 def names @names ||= links.collect(&:name).compact.uniq end |
#select(name) ⇒ Object
44 45 46 |
# File 'lib/pact_broker/client/hal/links.rb', line 44 def select(name) links.select{ | link | link.name == name } end |
#select!(name, not_found_message = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pact_broker/client/hal/links.rb', line 33 def select!(name, = nil) selected_links = select(name) if selected_links.any? selected_links else = || "Could not find relation '#{key}' with name '#{name}' in resource at #{href}." = names.any? ? names.join(", ") : "<none found>" raise RelationNotFoundError.new(.chomp(".") + ". Available options: #{}") end end |