class HALPresenter::CurieCollection::CurieWithReferences
Attributes
href[R]
name[RW]
references[R]
rels[R]
templated[R]
Public Class Methods
new(curie)
click to toggle source
# File lib/hal_presenter/curie_collection.rb, line 8 def initialize(curie) @name = curie.fetch(:name) @href = curie.fetch(:href) @templated = curie.fetch(:templated, true) @rels = Hash.new { |hash, key| hash[key] = Set.new } @references = Hash.new do |hash, key| hash[key] = Set.new.compare_by_identity end end
Public Instance Methods
<<(other)
click to toggle source
# File lib/hal_presenter/curie_collection.rb, line 23 def <<(other) other.rels.each do |type, rels| self.rels[type] += rels end other.references.each do |type, references| self.references[type] += references end end
add_reference(rel, reference, type)
click to toggle source
# File lib/hal_presenter/curie_collection.rb, line 18 def add_reference(rel, reference, type) rels[type] << rel references[type] << reference end
rename(name)
click to toggle source
# File lib/hal_presenter/curie_collection.rb, line 32 def rename(name) self.name = name rels.each do |type, rels| rels.each do |rel| new_rel = replace_curie(name, rel) references[type].each do |reference| reference[new_rel] = reference.delete(rel) end end end end
to_h()
click to toggle source
# File lib/hal_presenter/curie_collection.rb, line 45 def to_h { name: name, href: href, templated: templated } end
Private Instance Methods
replace_curie(name, rel)
click to toggle source
# File lib/hal_presenter/curie_collection.rb, line 57 def replace_curie(name, rel) _, rest = rel.to_s.split(':', 2) :"#{name}:#{rest}" end