Module: Psychgus::Styler

Included in:
Empty
Defined in:
lib/psychgus/styler.rb,
lib/psychgus/styler.rb

Overview

Mix in (include) this module to make a class/module/etc. a styler for YAML.

Although it's unnecessary (because of Duck Typing), it's the recommended practice in case a new method is added in the future, and also so you don't have to define methods that you don't use.

You can either use this as is (see example) or inside of a class (see Blueberry).

Examples:

class MyStyler
  include Psychgus::Styler

  def style_sequence(sniffer,node)
    node.style = Psychgus::SEQUENCE_FLOW if sniffer.level == 3
  end
end

hash = {'Coffee'=>{
          'Roast'=>['Light','Medium','Dark','Extra Dark'],
          'Style'=>['Cappuccino','Espresso','Latte','Mocha']
       }}
puts hash.to_yaml(stylers: MyStyler.new())

# Output:
# ---
# Coffee:
#   Roast: [Light, Medium, Dark, Extra Dark]
#   Style: [Cappuccino, Espresso, Latte, Mocha]

See Also:

Author:

  • Jonathan Bradley Whited (@esotericpig)

Since:

  • 1.0.0

Defined Under Namespace

Classes: Empty

Constant Summary collapse

EMPTY =

Since:

  • 1.0.0

Empty.new().freeze()

Instance Method Summary collapse

Instance Method Details

#style(sniffer, node) ⇒ Object

Style a node of any type.

You can use Ext::NodeExt#node_of? to determine its type:

puts node.value if node.node_of?(:scalar)

Parameters:

See Also:

Since:

  • 1.0.0


89
# File 'lib/psychgus/styler.rb', line 89

def style(sniffer,node) end

#style_alias(sniffer, node) ⇒ Object

Style a node guaranteed to be of type Psych::Nodes::Alias, to avoid if statements.

Parameters:

Since:

  • 1.0.0


95
# File 'lib/psychgus/styler.rb', line 95

def style_alias(sniffer,node) end

#style_document(sniffer, node) ⇒ Object

Style a node guaranteed to be of type Psych::Nodes::Document, to avoid if statements.

Parameters:

Since:

  • 1.0.0


101
# File 'lib/psychgus/styler.rb', line 101

def style_document(sniffer,node) end

#style_mapping(sniffer, node) ⇒ Object

Style a node guaranteed to be of type Psych::Nodes::Mapping, to avoid if statements.

Parameters:

Since:

  • 1.0.0


107
# File 'lib/psychgus/styler.rb', line 107

def style_mapping(sniffer,node) end

#style_scalar(sniffer, node) ⇒ Object

Style a node guaranteed to be of type Psych::Nodes::Scalar, to avoid if statements.

Parameters:

Since:

  • 1.0.0


113
# File 'lib/psychgus/styler.rb', line 113

def style_scalar(sniffer,node) end

#style_sequence(sniffer, node) ⇒ Object

Style a node guaranteed to be of type Psych::Nodes::Sequence, to avoid if statements.

Parameters:

Since:

  • 1.0.0


119
# File 'lib/psychgus/styler.rb', line 119

def style_sequence(sniffer,node) end

#style_stream(sniffer, node) ⇒ Object

Style a node guaranteed to be of type Psych::Nodes::Stream, to avoid if statements.

Parameters:

Since:

  • 1.0.0


125
# File 'lib/psychgus/styler.rb', line 125

def style_stream(sniffer,node) end