Class: HALPresenter::Links::Link
- Defined in:
- lib/hal_presenter/links.rb
Instance Attribute Summary collapse
-
#deprecation ⇒ Object
readonly
Returns the value of attribute deprecation.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#templated ⇒ Object
Returns the value of attribute templated.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Property
Instance Method Summary collapse
-
#initialize(rel, value = nil, **kwargs, &block) ⇒ Link
constructor
A new instance of Link.
- #to_h(resource = nil, options = {}) ⇒ Object
Methods inherited from Property
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
#deprecation ⇒ Object (readonly)
Returns the value of attribute deprecation.
20 21 22 |
# File 'lib/hal_presenter/links.rb', line 20 def deprecation @deprecation end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
20 21 22 |
# File 'lib/hal_presenter/links.rb', line 20 def profile @profile end |
#templated ⇒ Object
Returns the value of attribute templated.
21 22 23 |
# File 'lib/hal_presenter/links.rb', line 21 def templated @templated end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
20 21 22 |
# File 'lib/hal_presenter/links.rb', line 20 def title @title end |
#type ⇒ Object (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, = {}) href = value(resource, ) 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 |