Class: Psychgus::StyledDocumentStream

Inherits:
StyledTreeBuilder show all
Defined in:
lib/psychgus/styled_document_stream.rb

Overview

Use this wherever Psych::Handlers::DocumentStream would have been used, to enable styling.

See Also:

Author:

  • Jonathan Bradley Whited (@esotericpig)

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from StyledTreeBuilder

#deref_aliases, #sniffer, #stylers

Instance Method Summary collapse

Methods inherited from StyledTreeBuilder

#add_styler, #alias, #end_mapping, #end_sequence, #end_stream, #insert_styler, #pop_styler, #remove_styler, #remove_styler_at, #scalar, #start_mapping, #start_sequence, #start_stream

Constructor Details

#initialize(*stylers, deref_aliases: false, **options, &block) ⇒ StyledDocumentStream

Initialize this class with Psychgus::Styler(s) and a block.

Parameters:

  • stylers (Styler)

    Psychgus::Styler(s) to use for styling this DocumentStream

  • deref_aliases (true, false) (defaults to: false)

    whether to dereference aliases; output the actual value instead of the alias

  • block (Proc)

    a block to call in #end_document to denote a new YAML document

Since:

  • 1.0.0


44
45
46
47
48
# File 'lib/psychgus/styled_document_stream.rb', line 44

def initialize(*stylers,deref_aliases: false,**options,&block)
  super(*stylers,deref_aliases: deref_aliases,**options)
  
  @block = block
end

Instance Method Details

#end_document(implicit_end = !streaming?())) ⇒ Object

This mimics the behavior of Psych::Handlers::DocumentStream#end_document.

See Also:

  • Psych::Handlers::DocumentStream#end_document

Since:

  • 1.0.0


53
54
55
56
# File 'lib/psychgus/styled_document_stream.rb', line 53

def end_document(implicit_end=!streaming?())
  @last.implicit_end = implicit_end
  @block.call(pop)
end

#start_document(version, tag_directives, implicit) ⇒ Object

This mimics the behavior of Psych::Handlers::DocumentStream#start_document.

See Also:

  • Psych::Handlers::DocumentStream#start_document

Since:

  • 1.0.0


61
62
63
64
# File 'lib/psychgus/styled_document_stream.rb', line 61

def start_document(version,tag_directives,implicit)
  node = Psych::Nodes::Document.new(version,tag_directives,implicit)
  push(node)
end