Module: Rubyists::Namespacer

Defined in:
lib/namespacer.rb,
lib/namespacer/version.rb,
lib/namespacer/rewriter.rb

Overview

Namespace for the namespacer tool

Defined Under Namespace

Classes: Rewriter

Constant Summary collapse

VERSION =
'0.1.10'

Class Method Summary collapse

Class Method Details

.namespace!(string_or_io, namespaces) ⇒ String

Wrap some namespace(s) around top-level AST nodes of ‘module’ or ‘class’ type

Parameters:

  • string_or_io (String, IO)

    The source code to namespace

  • namespaces (String)

    The namespace(s) to wrap around the top-level AST nodes

Returns:

  • (String)

    The source code with the namespace(s) wrapped around the top-level AST nodes



20
21
22
23
24
25
26
# File 'lib/namespacer.rb', line 20

def self.namespace!(string_or_io, namespaces)
  buffer = Parser::Source::Buffer.new("(#{namespaces})")
  buffer.source = string_or_io.is_a?(IO) ? string_or_io.read : string_or_io
  parser = Parser::CurrentRuby.new
  rewriter = Rubyists::Namespacer::Rewriter.new namespaces
  rewriter.rewrite(buffer, parser.parse(buffer))
end