Module: JSONAPI::Serializable::Resource::Links
- Included in:
- JSONAPI::Serializable::Resource
- Defined in:
- lib/jsonapi/serializable/resource/links.rb
Overview
Mixin for handling resource links.
Defined Under Namespace
Modules: DSL
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.prepended(klass) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jsonapi/serializable/resource/links.rb', line 8 def self.prepended(klass) super klass.class_eval do extend DSL class << self attr_accessor :link_blocks end self.link_blocks = {} end end |
Instance Method Details
#as_jsonapi ⇒ Object
27 28 29 30 31 |
# File 'lib/jsonapi/serializable/resource/links.rb', line 27 def as_jsonapi(*) super.tap do |hash| hash[:links] = @_links if @_links.any? end end |
#initialize ⇒ Object
19 20 21 22 23 24 |
# File 'lib/jsonapi/serializable/resource/links.rb', line 19 def initialize(*) super @_links = self.class.link_blocks.each_with_object({}) do |(k, v), h| h[k] = Link.as_jsonapi(@_exposures, &v) end end |