jsonapi-serializable 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +0,0 @@
1
- module JSONAPI
2
- module Serializable
3
- class Resource
4
- # Mixin to handle resource type.
5
- module Type
6
- def self.prepended(klass)
7
- super
8
- klass.class_eval do
9
- extend DSL
10
- class << self
11
- attr_accessor :type_val, :type_block
12
- end
13
- end
14
- end
15
-
16
- def initialize(*)
17
- super
18
- @_type = if self.class.type_block
19
- instance_eval(&self.class.type_block).to_sym
20
- else
21
- self.class.type_val || :unknown
22
- end
23
- end
24
-
25
- # @see JSONAPI::Serializable::Resource#as_jsonapi
26
- def as_jsonapi(*)
27
- super.tap do |hash|
28
- hash[:type] = @_type
29
- end
30
- end
31
-
32
- # DSL methods for declaring the resource type.
33
- module DSL
34
- def inherited(klass)
35
- super
36
- klass.type_val = type_val
37
- klass.type_block = type_block
38
- end
39
-
40
- # @overload type(value)
41
- # Declare the JSON API type of this resource.
42
- # @param [String] value The value of the type.
43
- #
44
- # @example
45
- # type 'users'
46
- #
47
- # @overload type(&block)
48
- # Declare the JSON API type of this resource.
49
- # @yieldreturn [String] The value of the type.
50
- # @example
51
- # type do
52
- # @object.type
53
- # end
54
- def type(value = nil, &block)
55
- self.type_val = value.to_sym if value
56
- self.type_block = block
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end