Class: YARD::Serializers::Base Abstract
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
| 
         Subclasses: 
        
       | 
    |
| Inherits: | Object | 
| Defined in: | lib/yard/serializers/base.rb | 
Overview
Override this class to implement a custom serializer.
The abstract base serializer. ::YARD::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:
Creating a New Serializer
- 
    
      .new(opts = {})  ⇒ Base 
    
    constructor
    
Creates a new serializer with options.
 
Serializing an Object
- 
    
      #exists?(object)  ⇒ Boolean 
    
    abstract
    
Returns whether an object has been serialized.
 - 
    
      #serialize(object, data)  
    
    abstract
    
Serializes an object.
 - 
    
      #serialized_path(object)  ⇒ String 
    
    abstract
    
The serialized path of an object.
 
Callbacks
- 
    
      #after_serialize(data)  ⇒ void 
    
    abstract
    
Called after serialization.
 - 
    
      #before_serialize  ⇒ Boolean 
    
    abstract
    
Called before serialization.
 
Instance Attribute Summary
- 
    
      #options  ⇒ SymbolHash 
    
    readonly
    
All serializer options are saved so they can be passed to other serializers.
 
Constructor Details
    .new(opts = {})  ⇒ Base 
  
Creates a new serializer with options
# File 'lib/yard/serializers/base.rb', line 28
def initialize(opts = {}) @options = SymbolHash.new(false).update(opts) end
Instance Attribute Details
#options ⇒ SymbolHash (readonly)
All serializer options are saved so they can be passed to other serializers.
# File 'lib/yard/serializers/base.rb', line 21
attr_reader :
Instance Method Details
    #after_serialize(data)  ⇒ void 
  
Should run code after serialization.
This method returns an undefined value.
Called after serialization.
# File 'lib/yard/serializers/base.rb', line 80
def after_serialize(data); end
    #before_serialize  ⇒ Boolean 
  
Should run code before serialization. Should return false if serialization should not occur.
Called before serialization.
# File 'lib/yard/serializers/base.rb', line 73
def before_serialize; end
    #exists?(object)  ⇒ Boolean 
  
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
# File 'lib/yard/serializers/base.rb', line 62
def exists?(object) # rubocop:disable Lint/UnusedMethodArgument false end
#serialize(object, data)
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.
# File 'lib/yard/serializers/base.rb', line 42
def serialize(object, data) end
#serialized_path(object) ⇒ String
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
# File 'lib/yard/serializers/base.rb', line 51
def serialized_path(object) end