Class: YARD::Serializers::Base Abstract

Inherits:
Object
  • Object
show all
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:

Direct Known Subclasses

FileSystemSerializer, ProcessSerializer, StdoutSerializer

Instance Attribute Summary (collapse)

Creating a New Serializer (collapse)

Serializing an Object (collapse)

Callbacks (collapse)

Constructor Details

- (Base) initialize(opts = {})

Creates a new serializer with options

Parameters:

  • opts (Hash) (defaults to: {})

    the options to assign to #options



27
28
29
# File 'lib/yard/serializers/base.rb', line 27

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.

Returns:



20
21
22
# File 'lib/yard/serializers/base.rb', line 20

def options
  @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.

Parameters:

  • data (String)

    the data that was serialized.



77
# File 'lib/yard/serializers/base.rb', line 77

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.

Returns:

  • (Boolean)

    whether or not serialization should occur



70
# File 'lib/yard/serializers/base.rb', line 70

def before_serialize; end

- (Boolean) exists?(object)

This method is abstract.

This method should return whether the endpoint already exists. For instance, a file system serializer would check if the file exists on disk. You will most likely use #basepath and #serialized_path to get the endpoint's location.

Returns whether an object has been serialized

Parameters:

Returns:

  • (Boolean)

    whether the endpoint exists.

Since:

  • 0.6.0



61
# File 'lib/yard/serializers/base.rb', line 61

def exists?(object) false 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.

Parameters:

  • object (CodeObjects::Base, String)

    the object to serialize the data for. The object can also be a string (for non-object serialization)

  • data (String)

    the contents that should be serialized



41
# File 'lib/yard/serializers/base.rb', line 41

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

Parameters:

Returns:

  • (String)

    the serialized path of an object



50
# File 'lib/yard/serializers/base.rb', line 50

def serialized_path(object) end