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.
- checksums.yaml +4 -4
- data/lib/jsonapi/serializable/error.rb +6 -0
- data/lib/jsonapi/serializable/relationship.rb +2 -1
- data/lib/jsonapi/serializable/relationship/dsl.rb +4 -24
- data/lib/jsonapi/serializable/renderer.rb +62 -53
- data/lib/jsonapi/serializable/resource.rb +71 -16
- data/lib/jsonapi/serializable/resource/conditional_fields.rb +82 -42
- data/lib/jsonapi/serializable/resource/dsl.rb +173 -0
- data/lib/jsonapi/serializable/resource/key_format.rb +47 -29
- data/lib/jsonapi/serializable/resource/relationship.rb +62 -0
- data/lib/jsonapi/serializable/resource/relationship/dsl.rb +103 -0
- data/lib/jsonapi/serializable/resource_builder.rb +23 -43
- metadata +12 -12
- data/lib/jsonapi/serializable/fieldset.rb +0 -7
- data/lib/jsonapi/serializable/resource/attributes.rb +0 -73
- data/lib/jsonapi/serializable/resource/id.rb +0 -48
- data/lib/jsonapi/serializable/resource/links.rb +0 -67
- data/lib/jsonapi/serializable/resource/meta.rb +0 -62
- data/lib/jsonapi/serializable/resource/relationships.rb +0 -95
- data/lib/jsonapi/serializable/resource/temp_id.rb +0 -13
- data/lib/jsonapi/serializable/resource/temp_id.rb~ +0 -0
- data/lib/jsonapi/serializable/resource/type.rb +0 -62
@@ -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
|