Class: HALPresenter::Links::Link

Inherits:
Property
  • Object
show all
Defined in:
lib/hal_presenter/links.rb

Instance Attribute Summary collapse

Attributes inherited from Property

#embed_depth, #name

Instance Method Summary collapse

Methods inherited from Property

#change_context, #value

Constructor Details

#initialize(rel, value = nil, **kwargs, &block) ⇒ Link

Returns a new instance of Link.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hal_presenter/links.rb', line 25

def initialize(rel, value = nil, **kwargs, &block)
  @type =         kwargs[:type].freeze
  @deprecation =  kwargs[:deprecation].freeze
  @profile =      kwargs[:profile].freeze
  @title =        kwargs[:title].freeze

  curie = kwargs[:curie].to_s
  rel = [curie, rel.to_s].join(':') unless curie.empty?

  super(
    rel,
    value,
    embed_depth: kwargs[:embed_depth],
    context: kwargs[:context],
    &block
  )
end

Instance Attribute Details

#deprecationObject (readonly)

Returns the value of attribute deprecation.



20
21
22
# File 'lib/hal_presenter/links.rb', line 20

def deprecation
  @deprecation
end

#profileObject (readonly)

Returns the value of attribute profile.



20
21
22
# File 'lib/hal_presenter/links.rb', line 20

def profile
  @profile
end

#templatedObject

Returns the value of attribute templated.



21
22
23
# File 'lib/hal_presenter/links.rb', line 21

def templated
  @templated
end

#titleObject (readonly)

Returns the value of attribute title.



20
21
22
# File 'lib/hal_presenter/links.rb', line 20

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/hal_presenter/links.rb', line 20

def type
  @type
end

Instance Method Details

#to_h(resource = nil, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hal_presenter/links.rb', line 43

def to_h(resource = nil, options = {})
  href = value(resource, options)
  return {} unless href

  hash = {href: HALPresenter.href(href)}.tap do |h|
    h[:type] = type if type
    h[:deprecation] = deprecation if deprecation
    h[:profile] = profile if profile
    h[:title] = title if title
    h[:templated] = templated if templated
  end

  {rel => hash}
end