Sha256: f8beacd4595b3aa972c831b351a8a9c84553bb59ad67c891885051d1d4ad6478

Contents?: true

Size: 687 Bytes

Versions: 8

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true

require 'eac_cli/speaker/node'

module EacCli
  module Speaker
    class << self
      def current_node
        nodes_stack.last
      end

      def on_node(&block)
        push
        yield(*(block.arity.zero? ? [] : [current_node]))
      ensure
        pop
      end

      def push
        nodes_stack << ::EacCli::Speaker::Node.new
        current_node
      end

      def pop
        return nodes_stack.pop if nodes_stack.count > 1

        raise "Cannot remove first node (nodes_stack.count: #{nodes_stack.count})"
      end

      private

      def nodes_stack
        @nodes_stack ||= [::EacCli::Speaker::Node.new]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
eac_cli-0.19.0 lib/eac_cli/speaker/_class_methods.rb
avm-tools-0.101.0 vendor/eac_cli/lib/eac_cli/speaker/_class_methods.rb
eac_cli-0.18.0 lib/eac_cli/speaker/_class_methods.rb
avm-tools-0.100.0 vendor/eac_cli/lib/eac_cli/speaker/_class_methods.rb
ehbrs-tools-0.21.0 vendor/eac_cli/lib/eac_cli/speaker/_class_methods.rb
avm-tools-0.99.1 vendor/eac_cli/lib/eac_cli/speaker/_class_methods.rb
eac_cli-0.17.0 lib/eac_cli/speaker/_class_methods.rb
avm-tools-0.99.0 vendor/eac_cli/lib/eac_cli/speaker/_class_methods.rb