Module: SimpleJsonapi::Definition::Concerns::HasLinksObject
- Included in:
- Error, Relationship, Resource
- Defined in:
- lib/simple_jsonapi/definition/concerns/has_links_object.rb
Overview
Adds a #link method and #link_definitions collection to a definition.
Instance Attribute Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#link_definitions ⇒ Hash{Symbol => String,Object} (readonly)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_jsonapi/definition/concerns/has_links_object.rb', line 9 module HasLinksObject # @visibility private def self.included(base) base.send :attr_accessor, :link_definitions end def initialize(*args, &block) super @link_definitions = {} end private def initialize_dup(new_def) super new_def.link_definitions = link_definitions.deep_dup end # @overload link(name, options = {}, &block) # @overload link(name, value, options = {}) # @yieldparam object [Object] # @yieldreturn [String,Hash] # @return [void] def link(name, *args, **, &block) link_definitions[name.to_sym] = Link.new(name, *args, , &block) end end |
Instance Method Details
#initialize(*args, &block) ⇒ Object
15 16 17 18 |
# File 'lib/simple_jsonapi/definition/concerns/has_links_object.rb', line 15 def initialize(*args, &block) super @link_definitions = {} end |
#link(name, options = {}, &block) ⇒ void #link(name, value, options = {}) ⇒ void
This method returns an undefined value.
30 31 32 |
# File 'lib/simple_jsonapi/definition/concerns/has_links_object.rb', line 30 def link(name, *args, **, &block) link_definitions[name.to_sym] = Link.new(name, *args, , &block) end |