Class: Psych::Handler
| Relationships & Source Files | |
| Namespace Children | |
| Classes: | |
| Extension / Inclusion / Inheritance Descendants | |
| Subclasses: | |
| Inherits: | Object | 
| Defined in: | ext/psych/lib/psych/handler.rb, ext/psych/psych_emitter.c | 
Overview
Handler is an abstract base class that defines the events used when dealing with Parser.  Clients who want to use Parser should implement a class that inherits from Handler and define events that they can handle.
Handler defines all events that Parser can possibly send to event handlers.
See Parser for more details
Constant Summary
- 
    EVENTS =
    # File 'ext/psych/lib/psych/handler.rb', line 30Events that a Handlershould respond to.[ :alias, :empty, :end_document, :end_mapping, :end_sequence, :end_stream, :scalar, :start_document, :start_mapping, :start_sequence, :start_stream ] 
- 
    OPTIONS =
    # File 'ext/psych/lib/psych/handler.rb', line 27Default dumping options DumperOptions.new 
Instance Attribute Summary
- 
    
      #streaming?  ⇒ Boolean 
    
    readonly
    Is this handler a streaming handler? 
Instance Method Summary
- 
    
      #alias(anchor)  
    
    Called when an alias is found to anchor.
- 
    
      #empty  
    
    Called when an empty event happens. 
- 
    
      #end_document(implicit)  
    
    Called with the document ends. 
- 
    
      #end_mapping  
    
    Called when a map ends. 
- 
    
      #end_sequence  
    
    Called when a sequence ends. 
- 
    
      #end_stream  
    
    Called when the YAML stream ends. 
- 
    
      #event_location(start_line, start_column, end_line, end_column)  
    
    Called before each event with line/column information. 
- 
    
      #scalar(value, anchor, tag, plain, quoted, style)  
    
    Called when a scalar valueis found.
- 
    
      #start_document(version, tag_directives, implicit)  
    
    Called when the document starts with the declared version,tag_directives, if the document isimplicit.
- 
    
      #start_mapping(anchor, tag, implicit, style)  
    
    Called when a map starts. 
- 
    
      #start_sequence(anchor, tag, implicit, style)  
    
    Called when a sequence is started. 
- 
    
      #start_stream(encoding)  
    
    Called with encodingwhen the YAML stream starts.
Instance Attribute Details
    #streaming?  ⇒ Boolean  (readonly)
  
Is this handler a streaming handler?
# File 'ext/psych/lib/psych/handler.rb', line 251
def streaming? false end
Instance Method Details
#alias(anchor)
Called when an alias is found to anchor.  anchor will be the name of the anchor found.
Example
Here we have an example of an array that references itself in YAML:
--- &ponies
- first element
- *ponies&ponies is the anchor, *ponies is the alias. In this case, alias is called with “ponies”.
# File 'ext/psych/lib/psych/handler.rb', line 110
def alias anchor end
#empty
Called when an empty event happens. (Which, as far as I can tell, is never).
# File 'ext/psych/lib/psych/handler.rb', line 236
def empty end
#end_document(implicit)
Called with the document ends.  implicit is a boolean value indicating whether or not the document has an implicit ending.
Example
Given the following YAML:
---
  hello worldimplicit will be true.  Given this YAML:
---
  hello world
#...implicit will be false.
# File 'ext/psych/lib/psych/handler.rb', line 93
def end_document implicit end
#end_mapping
Called when a map ends
# File 'ext/psych/lib/psych/handler.rb', line 230
def end_mapping end
#end_sequence
Called when a sequence ends.
# File 'ext/psych/lib/psych/handler.rb', line 191
def end_sequence end
#end_stream
Called when the YAML stream ends
# File 'ext/psych/lib/psych/handler.rb', line 241
def end_stream end
#event_location(start_line, start_column, end_line, end_column)
Called before each event with line/column information.
# File 'ext/psych/lib/psych/handler.rb', line 246
def event_location(start_line, start_column, end_line, end_column) end
#scalar(value, anchor, tag, plain, quoted, style)
Called when a scalar value is found.  The scalar may have an anchor, a tag, be implicitly plain or implicitly quoted
value is the string value of the scalar anchor is an associated anchor or nil tag is an associated tag or nil plain is a boolean value quoted is a boolean value style is an integer indicating the string style
See the constants in Nodes::Scalar for the possible values of style
Example
Here is a YAML document that exercises most of the possible ways this method can be called:
---
- !str "foo"
- &anchor fun
- many
  lines
- |
  many
  newlinesThe above YAML document contains a list with four strings. Here are the parameters sent to this method in the same order:
# value               anchor    tag     plain   quoted  style
["foo",               nil,      "!str", false,  false,  3    ]
["fun",               "anchor", nil,    true,   false,  1    ]
["many lines",        nil,      nil,    true,   false,  1    ]
["many\nnewlines\n",  nil,      nil,    false,  true,   4    ]# File 'ext/psych/lib/psych/handler.rb', line 150
def scalar value, anchor, tag, plain, quoted, style end
#start_document(version, tag_directives, implicit)
Called when the document starts with the declared version, tag_directives, if the document is implicit.
version will be an array of integers indicating the YAML version being dealt with, tag_directives is a list of tuples indicating the prefix and suffix of each tag, and implicit is a boolean indicating whether the document is started implicitly.
Example
Given the following YAML:
%YAML 1.1
%TAG ! tag:tenderlovemaking.com,2009:
--- !squeeThe parameters for start_document must be this:
version         # => [1, 1]
tag_directives  # => [["!", "tag:tenderlovemaking.com,2009:"]]
implicit        # => false# File 'ext/psych/lib/psych/handler.rb', line 72
def start_document version, tag_directives, implicit end
#start_mapping(anchor, tag, implicit, style)
Called when a map starts.
anchor is the anchor associated with the map or nil. tag is the tag associated with the map or nil. implicit is a boolean indicating whether or not the map was implicitly started. style is an integer indicating the mapping style.
See the constants in Nodes::Mapping for the possible values of style.
Example
Here is a YAML document that exercises most of the possible ways this method can be called:
---
k: !!map { hello: world }
v: &pewpew
  hello: worldThe above YAML document consists of three maps, an outer map that contains two inner maps. Below is a matrix of the parameters sent in order to represent these three maps:
# anchor    tag                       implicit  style
[nil,       nil,                      true,     1     ]
[nil,       "tag:yaml.org,2002:map",  false,    2     ]
["pewpew",  nil,                      true,     1     ]# File 'ext/psych/lib/psych/handler.rb', line 225
def start_mapping anchor, tag, implicit, style end
#start_sequence(anchor, tag, implicit, style)
Called when a sequence is started.
anchor is the anchor associated with the sequence or nil. tag is the tag associated with the sequence or nil. implicit a boolean indicating whether or not the sequence was implicitly started. style is an integer indicating the list style.
See the constants in Nodes::Sequence for the possible values of style.
Example
Here is a YAML document that exercises most of the possible ways this method can be called:
---
- !!seq [
  a
]
- &pewpew
  - bThe above YAML document consists of three lists, an outer list that contains two inner lists. Here is a matrix of the parameters sent to represent these lists:
# anchor    tag                       implicit  style
[nil,       nil,                      true,     1     ]
[nil,       "tag:yaml.org,2002:seq",  false,    2     ]
["pewpew",  nil,                      true,     1     ]# File 'ext/psych/lib/psych/handler.rb', line 186
def start_sequence anchor, tag, implicit, style end
#start_stream(encoding)
Called with encoding when the YAML stream starts.  This method is called once per stream.  A stream may contain multiple documents.
See the constants in Parser for the possible values of encoding.
# File 'ext/psych/lib/psych/handler.rb', line 47
def start_stream encoding end