Module: HalApi::Representer::Curies::ClassMethods
- Defined in:
- lib/hal_api/representer/curies.rb
Constant Summary collapse
- LINK_RELATIONS =
%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
- #collection(name, options = {}) ⇒ Object
- #curies(curie, &block) ⇒ Object
- #curify(rel, curie = default_curie) ⇒ Object
- #link(options, &block) ⇒ Object
- #property(name, options = {}) ⇒ Object
- #use_curie(curie) ⇒ Object
Instance Method Details
#collection(name, options = {}) ⇒ Object
57 58 59 60 |
# File 'lib/hal_api/representer/curies.rb', line 57 def collection(name, ={}) [:as] = curify([:as] || name) if [:embedded] super(name, ) 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 |
#link(options, &block) ⇒ Object
46 47 48 49 50 |
# File 'lib/hal_api/representer/curies.rb', line 46 def link(, &block) = {:rel => } unless .is_a?(Hash) [:rel] = curify([:rel]) super(, &block) end |
#property(name, options = {}) ⇒ Object
52 53 54 55 |
# File 'lib/hal_api/representer/curies.rb', line 52 def property(name, ={}) [:as] = curify([:as] || name) if [:embedded] super(name, ) 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 |