Class: HALPresenter::Links::Link

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

Constant Summary

Constants inherited from Property

Property::NO_VALUE

Instance Attribute Summary collapse

Attributes inherited from Property

#embed_depth, #name

Instance Method Summary collapse

Methods inherited from Property

#change_context, #nested_depth_ok?, #value

Constructor Details

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

Returns a new instance of Link.



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

def initialize(rel, value = NO_VALUE, **kwargs, &block)
  @type =         kwargs[:type].freeze
  @deprecation =  kwargs[:deprecation].freeze
  @profile =      kwargs[:profile].freeze
  @title =        kwargs[:title].freeze
  @templated =    kwargs[:templated].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.



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

def deprecation
  @deprecation
end

#profileObject (readonly)

Returns the value of attribute profile.



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

def profile
  @profile
end

#templatedObject

Returns the value of attribute templated.



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

def templated
  @templated
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

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



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

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

  values = href.respond_to?(:to_h) ? href.to_h : {}
  values[:href] = HALPresenter.href(values[:href] || href)

  {
    type: type,
    deprecation: deprecation,
    profile: profile,
    title: title,
    templated: templated
  }.compact.merge(values)
end