Sha256: c52c7f919ea6b9ec8144e71c9be84392004c2005141081b54c68a1c3f57c1f60

Contents?: true

Size: 1.85 KB

Versions: 78

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true
require 'stringio'
require 'psych/class_loader'
require 'psych/scalar_scanner'

module Psych
  module Nodes
    ###
    # The base class for any Node in a YAML parse tree.  This class should
    # never be instantiated.
    class Node
      include Enumerable

      # The children of this node
      attr_reader :children

      # An associated tag
      attr_reader :tag

      # The line number where this node start
      attr_accessor :start_line

      # The column number where this node start
      attr_accessor :start_column

      # The line number where this node ends
      attr_accessor :end_line

      # The column number where this node ends
      attr_accessor :end_column

      # Create a new Psych::Nodes::Node
      def initialize
        @children = []
      end

      ###
      # Iterate over each node in the tree. Yields each node to +block+ depth
      # first.
      def each &block
        return enum_for :each unless block_given?
        Visitors::DepthFirst.new(block).accept self
      end

      ###
      # Convert this node to Ruby.
      #
      # See also Psych::Visitors::ToRuby
      def to_ruby(symbolize_names: false, freeze: false)
        Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze).accept(self)
      end
      alias :transform :to_ruby

      ###
      # Convert this node to YAML.
      #
      # See also Psych::Visitors::Emitter
      def yaml io = nil, options = {}
        real_io = io || StringIO.new(''.encode('utf-8'))

        Visitors::Emitter.new(real_io, options).accept self
        return real_io.string unless io
        io
      end
      alias :to_yaml :yaml

      def alias?;    false; end
      def document?; false; end
      def mapping?;  false; end
      def scalar?;   false; end
      def sequence?; false; end
      def stream?;   false; end
    end
  end
end

Version data entries

78 entries across 75 versions & 9 rubygems

Version Path
primary_connect_proto-0.7.1 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.7.0 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.6.0 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/psych-3.3.2/lib/psych/nodes/node.rb
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.4.0 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.3.0 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/psych-4.0.2/lib/psych/nodes/node.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/psych-4.0.2/lib/psych/nodes/node.rb