class ToFactory::Parsing::Syntax
Attributes
contents[RW]
Public Class Methods
new(contents)
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 17 def initialize(contents) @contents = contents end
Public Instance Methods
factories()
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 43 def factories if multiple_factories? factories_sexp[1..-1] else [factories_sexp] end end
factories_sexp()
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 51 def factories_sexp header? ? sexp[3] : sexp end
header?()
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 61 def header? sexp[1][1][1] == :FactoryGirl rescue false end
multiple_factories?()
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 21 def multiple_factories? factories_sexp[0] == :block end
name_from(sexp)
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 55 def name_from(sexp) sexp[1][3][1] rescue NoMethodError raise CouldNotInferClassException.new(sexp) end
parent_from(x)
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 65 def parent_from(x) # e.g. #s(:call, nil, :factory, s(:lit, :admin), s(:hash, s(:lit, :parent), s(:lit, :"to_factory/user"))) x[1][4][2][1] rescue NoMethodError # e.g. #s(:call, nil, :factory, s(:lit, :"to_factory/user")) x[1][3][1] end
parse()
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 25 def parse factories.map do |x| representation_from(x) end rescue Racc::ParseError, StringScanner::Error => e raise ParseException.new("Original exception: #{e.message}\n #{e.backtrace.join("\n")}\nToFactory Error parsing \n#{@contents}\n o") end
representation_from(x)
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 35 def representation_from(x) Representation.new(name_from(x), parent_from(x), to_ruby(x)) rescue CouldNotInferClassException => e ruby = to_ruby(e.sexp) Kernel.warn "ToFactory could not parse\n#{ruby}" NullRepresentation.new(e.sexp) end
Private Instance Methods
sexp()
click to toggle source
# File lib/to_factory/parsing/syntax.rb, line 77 def sexp @sexp ||= ruby_parser.process(@contents) end