lib/ripper/extract_constants.rb in grape-reload-0.0.4 vs lib/ripper/extract_constants.rb in grape-reload-0.1.0
- old
+ new
@@ -195,11 +195,11 @@
end
class ASTBody < ASTEntity
def self.ripper_id; :bodystmt end
def initialize(*args)
- @body = args.first.map{ |node| ASTEntity.node_for(node) }
+ @body = args.reject(&:nil?).map{ |node| ASTEntity.node_for(node) }
end
def collect_constants(result, context)
context[:variable_assignment] = false
super(result, context)
end
@@ -348,13 +348,11 @@
class ASTModule < ASTEntity
def self.ripper_id; :module end
def initialize(*args)
@module_name = args.find{|a| a.first == :const_ref}.last[1]
- @body = args.find{|a| a.first == :bodystmt}[1].map{|node|
- ASTEntity.node_for(node)
- }
+ @body = [ASTEntity.node_for(args.find{|a| a.first == :bodystmt})]
end
def collect_constants(result, context)
result.declare_const(@module_name)
result = result.nest(@module_name)
context.module << @module_name
@@ -385,12 +383,33 @@
def initialize(*args)
super(*(args[0..-2]))
end
end
+class ASTStatementsAdd < ASTEntity
+ def self.ripper_id; :stmts_add end
+ def initialize(*args)
+ super(*args)
+ end
+end
+
+class ASTStatementsNew < ASTEntity
+ def self.ripper_id; :stmts_new end
+ def initialize(*args)
+ super(*args)
+ end
+end
+
+class ASTStatementsProgram < ASTEntity
+ def self.ripper_id; :program end
+ def initialize(*args)
+ super(args.first)
+ end
+end
+
class Ripper
def self.extract_constants(code)
- ast = Ripper.sexp(code)
+ ast = Ripper.sexp_raw(code)
result = ASTEntity.node_for(ast).collect_constants(TraversingResult.new)
consts = result.extract_consts
consts[:declared].flatten!
consts[:declared].uniq!
consts