Class: BooticClient::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_client/relation.rb

Constant Summary collapse

GET =
'get'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs, client, wrapper_class = Entity) ⇒ Relation

Returns a new instance of Relation.



10
11
12
# File 'lib/bootic_client/relation.rb', line 10

def initialize(attrs, client, wrapper_class = Entity)
  @attrs, @client, @wrapper_class = attrs, client, wrapper_class
end

Class Method Details

.expand(href, opts = {}) ⇒ Object



54
55
56
# File 'lib/bootic_client/relation.rb', line 54

def self.expand(href, opts = {})
  URITemplate.new(href).expand(opts)
end

Instance Method Details

#docs ⇒ Object



38
39
40
# File 'lib/bootic_client/relation.rb', line 38

def docs
  attrs['docs']
end

#href ⇒ Object



18
19
20
# File 'lib/bootic_client/relation.rb', line 18

def href
  attrs['href']
end

#inspect ⇒ Object



14
15
16
# File 'lib/bootic_client/relation.rb', line 14

def inspect
  %(#<#{self.class.name} #{attrs.inspect}>)
end

#name ⇒ Object



26
27
28
# File 'lib/bootic_client/relation.rb', line 26

def name
  attrs['name']
end

#run(opts = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/bootic_client/relation.rb', line 46

def run(opts = {})
  if templated?
    client.request_and_wrap transport_method.to_sym, uri.expand(opts), wrapper_class, opts
  else
    client.request_and_wrap transport_method.to_sym, href, wrapper_class, opts
  end
end

#templated? ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/bootic_client/relation.rb', line 22

def templated?
  !!attrs['templated']
end

#title ⇒ Object



30
31
32
# File 'lib/bootic_client/relation.rb', line 30

def title
  attrs['title']
end

#transport_method ⇒ Object



42
43
44
# File 'lib/bootic_client/relation.rb', line 42

def transport_method
  @transport_method ||= attrs['method'] || GET
end

#type ⇒ Object



34
35
36
# File 'lib/bootic_client/relation.rb', line 34

def type
  attrs['type']
end