Module: JSONAPI::Serializable::Resource::Type
- Included in:
- JSONAPI::Serializable::Resource
- Defined in:
- lib/jsonapi/serializable/resource/type.rb
Overview
Mixin to handle resource type.
Defined Under Namespace
Modules: DSL
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.prepended(klass) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/jsonapi/serializable/resource/type.rb', line 6 def self.prepended(klass) super klass.class_eval do extend DSL class << self attr_accessor :type_val, :type_block end end end |
Instance Method Details
#as_jsonapi ⇒ Object
26 27 28 29 30 |
# File 'lib/jsonapi/serializable/resource/type.rb', line 26 def as_jsonapi(*) super.tap do |hash| hash[:type] = @_type end end |
#initialize ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/jsonapi/serializable/resource/type.rb', line 16 def initialize(*) super @_type = if self.class.type_block instance_eval(&self.class.type_block).to_sym else self.class.type_val || :unknown end end |