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