Class: Synvert::BaseConverter

Inherits:
Parser::Rewriter
  • Object
show all
Includes:
AST::Sexp, SexpHelper
Defined in:
lib/synvert/base_converter.rb

Direct Known Subclasses

FactoryGirl::SyntaxMethodsConverter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SexpHelper

#body, #contains_statement?, #message, #name, #receiver, #to_ast

Instance Attribute Details

#filename ⇒ Object (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/synvert/base_converter.rb', line 8

def filename
  @filename
end

Instance Method Details

#append_after(node, content) ⇒ Object



27
28
29
30
# File 'lib/synvert/base_converter.rb', line 27

def append_after(node, content)
  indent = indent(node)
  insert_after node.loc.expression, "\n#{' '*indent}#{content}"
end

#append_to(node, content) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/synvert/base_converter.rb', line 17

def append_to(node, content)
  if node.children.last
    indent = indent(node.children.last)
    insert_after node.children.last.loc.expression, "\n#{' '*indent}#{content}"
  else
    indent = indent(node) + 2
    insert_after node.children.first.loc.expression, "\n#{' '*indent}#{content}"
  end
end

#indent(node) ⇒ Object



32
33
34
# File 'lib/synvert/base_converter.rb', line 32

def indent(node)
  node.loc.expression.column
end

#rewrite(source_buffer, ast) ⇒ Object



10
11
12
13
14
15
# File 'lib/synvert/base_converter.rb', line 10

def rewrite(source_buffer, ast)
  @filename = source_buffer.name

  new_ast = AST::Node.new(:program, [ast])
  super(source_buffer, new_ast)
end