Class: Xing::Serializers::Base
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Xing::Serializers::Base
show all
- Defined in:
- lib/xing/serializers/base.rb
Overview
The base class for all Xing serializers that produce Xing Hypermedia JSON resources. In general, subclasses of Xing::Serializers::Base should:
* Define a links method that returns a hash of hypermedia links to
related resources
* Specify the attributes (via the ActiveModel::Serializers 'attributes'
class method) that will be copied into the data: block
of the generated resource.
* Define methods for any attributes that do not exist as plain attributes
in the ActiveModel being serialized. Note that this may (and often will) include
calling other serializers on related resources or other data, in order to
generate embedded resources.
Xing serializers descend from ActiveModel::Serializer and are typically instantiated with an instance of an ActiveModel model in the usual way.
Instance Method Summary
collapse
Instance Method Details
#as_json_with_wrap(options = {}) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/xing/serializers/base.rb', line 36
def as_json_with_wrap(options={})
{
:links => links,
:data => as_json_without_wrap
}
end
|
#links ⇒ Object
43
44
45
|
# File 'lib/xing/serializers/base.rb', line 43
def links
{}
end
|
#root ⇒ Object
32
33
34
|
# File 'lib/xing/serializers/base.rb', line 32
def root
false
end
|
#routes ⇒ Object
28
29
30
|
# File 'lib/xing/serializers/base.rb', line 28
def routes
Rails.application.routes.url_helpers
end
|