Class: YARD::Serializers::Base Abstract
- Inherits:
-
Object
- Object
- YARD::Serializers::Base
- Defined in:
- lib/yard/serializers/base.rb
Overview
This class is abstract. Override this class to implement a custom serializer.
The abstract base serializer. Serializers allow templates to be rendered to various endpoints. For instance, a FileSystemSerializer would allow template contents to be written to the filesystem
To implement a custom serializer, override the following methods:
Optionally, a serializer can implement before and after filters:
Instance Attribute Summary
- - (SymbolHash) options readonly All serializer options are saved so they can be passed to other serializers.
Instance Method Summary
- - (void) after_serialize(data) Abstract Called after serialization.
- - (Boolean) before_serialize Abstract Called before serialization.
- - (Base) initialize(opts = {}) constructor Creates a new serializer with options.
- - (Object) serialize(object, data) Abstract Serializes an object.
- - (String) serialized_path(object) Abstract The serialized path of an object.
Constructor Details
- (Base) initialize(opts = {})
Creates a new serializer with options
25 26 27 |
# File 'lib/yard/serializers/base.rb', line 25 def initialize(opts = {}) @options = SymbolHash.new(false).update(opts) end |
Instance Attribute Details
- (SymbolHash) options (readonly)
All serializer options are saved so they can be passed to other serializers.
20 21 22 |
# File 'lib/yard/serializers/base.rb', line 20 def @options end |
Instance Method Details
- (void) after_serialize(data)
This method is abstract. Should run code after serialization.
This method returns an undefined value.
Called after serialization.
41 |
# File 'lib/yard/serializers/base.rb', line 41 def after_serialize(data); end |
- (Boolean) before_serialize
This method is abstract. Should run code before serialization. Should return false if serialization should not occur.
Called before serialization.
34 |
# File 'lib/yard/serializers/base.rb', line 34 def before_serialize; end |
- (Object) serialize(object, data)
This method is abstract. This method should implement the logic that serializes data to the respective endpoint. This method should also call the before and after callbacks #before_serialize and #after_serialize
Serializes an object.
51 |
# File 'lib/yard/serializers/base.rb', line 51 def serialize(object, data) end |
- (String) serialized_path(object)
This method is abstract. This method should return the path of the object on the endpoint. For instance, for a file serializer, this should return the filename that represents the object on disk.
The serialized path of an object
60 |
# File 'lib/yard/serializers/base.rb', line 60 def serialized_path(object) end |