Class: CollectionJson::Serializer
- Inherits:
-
Object
- Object
- CollectionJson::Serializer
show all
- Defined in:
- lib/collection_json_serializer/items.rb,
lib/collection_json_serializer/builder.rb,
lib/collection_json_serializer/support.rb,
lib/collection_json_serializer/version.rb,
lib/collection_json_serializer/validator.rb,
lib/collection_json_serializer/serializer.rb,
lib/collection_json_serializer/objects/item.rb,
lib/collection_json_serializer/objects/query.rb,
lib/collection_json_serializer/validator/base.rb,
lib/collection_json_serializer/objects/template.rb,
lib/collection_json_serializer/validator/types/url.rb,
lib/collection_json_serializer/validator/types/value.rb,
lib/collection_json_serializer/validator/items_validator.rb
Defined Under Namespace
Modules: Support
Classes: Builder, Items, Objects, Validation, Validator
Constant Summary
collapse
- VERSION =
"0.4.0"
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource) ⇒ Serializer
Returns a new instance of Serializer.
60
61
62
63
64
65
66
|
# File 'lib/collection_json_serializer/serializer.rb', line 60
def initialize(resource)
@resources = if resource.respond_to? :to_ary
resource
else
[resource]
end
end
|
Class Attribute Details
._extensions ⇒ Object
Returns the value of attribute _extensions.
4
5
6
|
# File 'lib/collection_json_serializer/serializer.rb', line 4
def _extensions
@_extensions
end
|
._href ⇒ Object
Returns the value of attribute _href.
5
6
7
|
# File 'lib/collection_json_serializer/serializer.rb', line 5
def _href
@_href
end
|
._items ⇒ Object
Returns the value of attribute _items.
9
10
11
|
# File 'lib/collection_json_serializer/serializer.rb', line 9
def _items
@_items
end
|
._links ⇒ Object
Returns the value of attribute _links.
7
8
9
|
# File 'lib/collection_json_serializer/serializer.rb', line 7
def _links
@_links
end
|
._queries ⇒ Object
Returns the value of attribute _queries.
8
9
10
|
# File 'lib/collection_json_serializer/serializer.rb', line 8
def _queries
@_queries
end
|
._template ⇒ Object
Returns the value of attribute _template.
6
7
8
|
# File 'lib/collection_json_serializer/serializer.rb', line 6
def _template
@_template
end
|
Instance Attribute Details
#resources ⇒ Object
Returns the value of attribute resources.
58
59
60
|
# File 'lib/collection_json_serializer/serializer.rb', line 58
def resources
@resources
end
|
Class Method Details
.extensions(*attrs) ⇒ Object
20
21
22
|
# File 'lib/collection_json_serializer/serializer.rb', line 20
def self.extensions(*attrs)
@_extensions.concat attrs
end
|
.href(*attrs) ⇒ Object
24
25
26
|
# File 'lib/collection_json_serializer/serializer.rb', line 24
def self.href(*attrs)
@_href.concat attrs
end
|
.inherited(base) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/collection_json_serializer/serializer.rb', line 12
def self.inherited(base)
base._extensions = []
base._href = []
base._template = []
base._links = []
base._queries = []
end
|
.items(&block) ⇒ Object
53
54
55
56
|
# File 'lib/collection_json_serializer/serializer.rb', line 53
def self.items(&block)
@_items = Items.new
@_items.instance_eval(&block)
end
|
.link(*attrs) ⇒ Object
32
33
34
|
# File 'lib/collection_json_serializer/serializer.rb', line 32
def self.link(*attrs)
@_links.concat attrs
end
|
.links(*attrs) ⇒ Object
37
38
39
40
41
|
# File 'lib/collection_json_serializer/serializer.rb', line 37
def self.links(*attrs)
warn "links has been deprecated and will be removed soon. " <<
"Please, use `link` instead"
@_links.concat attrs
end
|
.queries(*attrs) ⇒ Object
47
48
49
50
51
|
# File 'lib/collection_json_serializer/serializer.rb', line 47
def self.queries(*attrs)
warn "`queries` has been deprecated and will be removed soon. " <<
"Please, use `query` instead"
@_queries.concat attrs
end
|
.query(*attrs) ⇒ Object
43
44
45
|
# File 'lib/collection_json_serializer/serializer.rb', line 43
def self.query(*attrs)
@_queries.concat attrs
end
|
.template(*attrs) ⇒ Object
28
29
30
|
# File 'lib/collection_json_serializer/serializer.rb', line 28
def self.template(*attrs)
@_template.concat attrs
end
|
Instance Method Details
#errors ⇒ Object
120
121
122
|
# File 'lib/collection_json_serializer/serializer.rb', line 120
def errors
Validator.new(self).errors
end
|
#extensions ⇒ Object
68
69
70
|
# File 'lib/collection_json_serializer/serializer.rb', line 68
def extensions
self.class._extensions
end
|
#href ⇒ Object
72
73
74
|
# File 'lib/collection_json_serializer/serializer.rb', line 72
def href
self.class._href.first
end
|
#invalid? ⇒ Boolean
112
113
114
|
# File 'lib/collection_json_serializer/serializer.rb', line 112
def invalid?
Validator.new(self).invalid?
end
|
#items ⇒ Object
100
101
102
|
# File 'lib/collection_json_serializer/serializer.rb', line 100
def items
self.class._items
end
|
#items? ⇒ Boolean
104
105
106
|
# File 'lib/collection_json_serializer/serializer.rb', line 104
def items?
self.class._items.present?
end
|
#links ⇒ Object
84
85
86
|
# File 'lib/collection_json_serializer/serializer.rb', line 84
def links
self.class._links
end
|
#links? ⇒ Boolean
88
89
90
|
# File 'lib/collection_json_serializer/serializer.rb', line 88
def links?
self.class._links.present?
end
|
#queries ⇒ Object
92
93
94
|
# File 'lib/collection_json_serializer/serializer.rb', line 92
def queries
self.class._queries
end
|
#queries? ⇒ Boolean
96
97
98
|
# File 'lib/collection_json_serializer/serializer.rb', line 96
def queries?
self.class._queries.present?
end
|
#template ⇒ Object
76
77
78
|
# File 'lib/collection_json_serializer/serializer.rb', line 76
def template
self.class._template
end
|
#template? ⇒ Boolean
80
81
82
|
# File 'lib/collection_json_serializer/serializer.rb', line 80
def template?
self.class._template.present?
end
|
#uses?(extension) ⇒ Boolean
108
109
110
|
# File 'lib/collection_json_serializer/serializer.rb', line 108
def uses?(extension)
extensions.include?(extension)
end
|
#valid? ⇒ Boolean
116
117
118
|
# File 'lib/collection_json_serializer/serializer.rb', line 116
def valid?
Validator.new(self).valid?
end
|