Module: HALPresenter::Links
Defined Under Namespace
Modules: ClassMethods
Classes: Link
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
62
63
64
|
# File 'lib/hal_presenter/links.rb', line 62
def self.included(base)
base.extend ClassMethods
end
|
Instance Method Details
#link(rel, value = nil, **kwargs, &block) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/hal_presenter/links.rb', line 66
def link(rel, value = nil, **kwargs, &block)
if value.nil? && !block_given?
raise 'link must be called with non nil value or be given a block'
end
kwargs[:context] ||= self
rel = rel.to_sym
if rel == :self || kwargs[:replace_parent]
links.delete_if { |link| link.rel == rel }
end
Link.new(rel, value, **kwargs, &block).tap do |link|
links << link
end
end
|