Class: Leadlight::Link

Inherits:
Object
  • Object
show all
Includes:
Leadlight
Defined in:
lib/leadlight/link.rb

Direct Known Subclasses

LinkTemplate

Constant Summary collapse

HTTP_METHODS_WITH_BODY =
[:post, :put, :patch]
HTTP_METHODS_WITHOUT_BODY =
[
  :options, :head, :get, :get_representation!, :delete
]
HTTP_METHODS =
HTTP_METHODS_WITHOUT_BODY + HTTP_METHODS_WITH_BODY

Constants included from Leadlight

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Leadlight

ParamHash, build_connection_common, build_service, common_connection_stack

Constructor Details

#initialize(service, href, rel = nil, title = rel, options = {}) ⇒ Link

Returns a new instance of Link.



28
29
30
31
32
33
34
35
36
37
# File 'lib/leadlight/link.rb', line 28

def initialize(service, href, rel=nil, title=rel, options={})
  @options = options
  @service = service
  @href    = Addressable::URI.parse(href)
  @rel     = rel.to_s
  @title   = title.to_s
  @rev     = options[:rev]
  @aliases = Array(options[:aliases])
  self.expansion_params = options.fetch(:expansion_params) { {} }
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



20
21
22
# File 'lib/leadlight/link.rb', line 20

def aliases
  @aliases
end

#expansion_paramsObject

Expansion params have no effect on the Link. They exist to keep a record of how this particular Link instance was constructed, if it was constructed via expansion.



26
27
28
# File 'lib/leadlight/link.rb', line 26

def expansion_params
  @expansion_params
end

#hrefObject

Returns the value of attribute href.



19
20
21
# File 'lib/leadlight/link.rb', line 19

def href
  @href
end

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/leadlight/link.rb', line 21

def options
  @options
end

#relObject (readonly)

Returns the value of attribute rel.



16
17
18
# File 'lib/leadlight/link.rb', line 16

def rel
  @rel
end

#revObject (readonly)

Returns the value of attribute rev.



17
18
19
# File 'lib/leadlight/link.rb', line 17

def rev
  @rev
end

#serviceObject (readonly)

Returns the value of attribute service.



15
16
17
# File 'lib/leadlight/link.rb', line 15

def service
  @service
end

#titleObject (readonly)

Returns the value of attribute title.



18
19
20
# File 'lib/leadlight/link.rb', line 18

def title
  @title
end

Instance Method Details

#[](*args) ⇒ Object



74
75
76
# File 'lib/leadlight/link.rb', line 74

def [](*args)
  expand(*args)
end

#expand(expansion_params = nil) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/leadlight/link.rb', line 66

def expand(expansion_params=nil)
  if expansion_params
    dup_with_new_href(expand_uri_with_params(href.dup, expansion_params), expansion_params)
  else
    self
  end
end

#follow(*args) ⇒ Object



60
61
62
63
64
# File 'lib/leadlight/link.rb', line 60

def follow(*args)
  get_representation!(*args) do |representation|
    return representation
  end
end

#paramsObject



82
83
84
# File 'lib/leadlight/link.rb', line 82

def params
  extracted_params.merge(expansion_params)
end

#to_sObject



78
79
80
# File 'lib/leadlight/link.rb', line 78

def to_s
  "Link(#{rel}:#{href}#{inspect_expansion_params})"
end