Module: HalApi::Representer::Curies::ClassMethods

Defined in:
lib/hal_api/representer/curies.rb

Constant Summary collapse

%w(about alternate appendix archives author bookmark
canonical chapter collection contents copyright create-form curies current
describedby describes disclosure duplicate edit edit-form edit-media
enclosure first glossary help hosts hub icon index item last latest-version
license lrdd memento monitor monitor-group next next-archive nofollow
noreferrer original payment predecessor-version prefetch prev preview
previous prev-archive privacy-policy profile related replies search section
self service start stylesheet subsection successor-version tag
terms-of-service timegate timemap type up version-history via working-copy
working-copy-of)

Instance Method Summary collapse

Instance Method Details

#collection(name, options = {}) ⇒ Object



57
58
59
60
# File 'lib/hal_api/representer/curies.rb', line 57

def collection(name, options={})
  options[:as] = curify(options[:as] || name) if options[:embedded]
  super(name, options)
end

#curies(curie, &block) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/hal_api/representer/curies.rb', line 29

def curies(curie, &block)
  use_curie(curie) unless default_curie
  link({rel: :curies, array: true}) do
    if represented.try(:show_curies)
      block.call
    end
  end
end

#curify(rel, curie = default_curie) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/hal_api/representer/curies.rb', line 38

def curify(rel, curie=default_curie)
  if curie.blank? || rel.to_s =~ /:/ || LINK_RELATIONS.include?(rel.to_s)
    rel
  else
    "#{curie}:#{rel}".to_sym
  end
end


46
47
48
49
50
# File 'lib/hal_api/representer/curies.rb', line 46

def link(options, &block)
  options = {:rel => options} unless options.is_a?(Hash)
  options[:rel] = curify(options[:rel])
  super(options, &block)
end

#property(name, options = {}) ⇒ Object



52
53
54
55
# File 'lib/hal_api/representer/curies.rb', line 52

def property(name, options={})
  options[:as] = curify(options[:as] || name) if options[:embedded]
  super(name, options)
end

#use_curie(curie) ⇒ Object



25
26
27
# File 'lib/hal_api/representer/curies.rb', line 25

def use_curie(curie)
  self.default_curie = curie
end