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.2"
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.
62
63
64
65
66
67
68
|
# File 'lib/collection_json_serializer/serializer.rb', line 62
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.
60
61
62
|
# File 'lib/collection_json_serializer/serializer.rb', line 60
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
55
56
57
58
|
# File 'lib/collection_json_serializer/serializer.rb', line 55
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
42
|
# File 'lib/collection_json_serializer/serializer.rb', line 37
def self.links(*attrs)
warn "Warning from collection_json_serializer\n" <<
"`links` has been deprecated and will be removed soon. " <<
"Please, use `link` instead"
@_links.concat attrs
end
|
.queries(*attrs) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/collection_json_serializer/serializer.rb', line 48
def self.queries(*attrs)
warn "Warning from collection_json_serializer\n" <<
"`queries` has been deprecated and will be removed soon. " <<
"Please, use `query` instead"
@_queries.concat attrs
end
|
.query(*attrs) ⇒ Object
44
45
46
|
# File 'lib/collection_json_serializer/serializer.rb', line 44
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
122
123
124
|
# File 'lib/collection_json_serializer/serializer.rb', line 122
def errors
Validator.new(self).errors
end
|
#extensions ⇒ Object
70
71
72
|
# File 'lib/collection_json_serializer/serializer.rb', line 70
def extensions
self.class._extensions
end
|
#href ⇒ Object
74
75
76
|
# File 'lib/collection_json_serializer/serializer.rb', line 74
def href
self.class._href.first
end
|
#invalid? ⇒ Boolean
114
115
116
|
# File 'lib/collection_json_serializer/serializer.rb', line 114
def invalid?
Validator.new(self).invalid?
end
|
#items ⇒ Object
102
103
104
|
# File 'lib/collection_json_serializer/serializer.rb', line 102
def items
self.class._items
end
|
#items? ⇒ Boolean
106
107
108
|
# File 'lib/collection_json_serializer/serializer.rb', line 106
def items?
self.class._items.present?
end
|
#links ⇒ Object
86
87
88
|
# File 'lib/collection_json_serializer/serializer.rb', line 86
def links
self.class._links
end
|
#links? ⇒ Boolean
90
91
92
|
# File 'lib/collection_json_serializer/serializer.rb', line 90
def links?
self.class._links.present?
end
|
#queries ⇒ Object
94
95
96
|
# File 'lib/collection_json_serializer/serializer.rb', line 94
def queries
self.class._queries
end
|
#queries? ⇒ Boolean
98
99
100
|
# File 'lib/collection_json_serializer/serializer.rb', line 98
def queries?
self.class._queries.present?
end
|
#template ⇒ Object
78
79
80
|
# File 'lib/collection_json_serializer/serializer.rb', line 78
def template
self.class._template
end
|
#template? ⇒ Boolean
82
83
84
|
# File 'lib/collection_json_serializer/serializer.rb', line 82
def template?
self.class._template.present?
end
|
#uses?(extension) ⇒ Boolean
110
111
112
|
# File 'lib/collection_json_serializer/serializer.rb', line 110
def uses?(extension)
extensions.include?(extension)
end
|
#valid? ⇒ Boolean
118
119
120
|
# File 'lib/collection_json_serializer/serializer.rb', line 118
def valid?
Validator.new(self).valid?
end
|