class TurboTest::StaticAnalysis::ActiveRecord::SexpBuilder
Constants
- COMMANDS
- COMMAND_REGEXP
- TABLE_REGEXP
- TRIGGER_REGEXP
Attributes
schema[RW]
Public Class Methods
new(path, filename = "-", lineno = 1)
click to toggle source
Calls superclass method
TurboTest::StaticAnalysis::ActiveRecord::LineStackSexpBuilder::new
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 18 def initialize(path, filename = "-", lineno = 1) super @schema_file = path.split("\n") @schema = Constructor.new end
snapshot_from_file(path)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 24 def self.snapshot_from_file(path) builder = new(File.read(path), path) builder.parse builder.snapshot end
snapshot_from_source(source)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 30 def self.snapshot_from_source(source) builder = new(source) builder.parse builder.snapshot end
Public Instance Methods
on_command(token_one, token_two)
click to toggle source
Calls superclass method
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 40 def on_command(token_one, token_two) super.tap do |_result| name = token_one[1] next unless COMMANDS.include? name last_line = @stack.remove_greater_than([lineno, column]) content = method_content(lineno, last_line[0]) @schema.send(name.to_sym, table_name(:command, token_two), content) end end
on_method_add_block(token_one, token_two)
click to toggle source
Calls superclass method
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 51 def on_method_add_block(token_one, token_two) super.tap do |_result| next unless (type = type_for_token(token_one[0])) first_line, last_line = send("#{type}_lines", token_one) handle_create(type, token_one, first_line, last_line) end end
snapshot()
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 36 def snapshot @schema.snapshot end
Private Instance Methods
extract_fcall(token)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 110 def extract_fcall(token) case token[0] when :fcall [token[1][1], token[1][2]] when :call extract_fcall(token[1][1]) else [] end end
handle_create(type, token, line_start, line_end)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 87 def handle_create(type, token, line_start, line_end) return unless line_start && line_end table = table_name(type, token) content = method_content(line_start, line_end) @schema.send("create_#{type}".to_sym, table, content) end
lines_str(from, to)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 121 def lines_str(from, to) from -= 1 to -= 1 @schema_file[from..to].join("") end
method_content(start_line, end_line)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 106 def method_content(start_line, end_line) lines_str(start_line, end_line) end
table_lines(token)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 71 def table_lines(token) return unless token[1][1] == "create_table" last_line = @stack.remove_greater_than(token[1][2]) [token[1][2][0], last_line[0]] end
table_name(type, token)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 95 def table_name(type, token) regexp = self.class.const_get "#{type.upcase}_REGEXP" match = Sorcerer.source(token).match(regexp) case type when :trigger match[1..2][1] else match[1] end end
trigger_lines(token)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 78 def trigger_lines(token) fcall = extract_fcall(token[1]) return unless fcall[0] == "create_trigger" first_line = fcall[1] last_line = @stack.remove_greater_than(first_line) [first_line[0], last_line[0]] end
type_for_token(token)
click to toggle source
# File lib/turbo_test_static_analysis/active_record_schema/sexp_builder/sexp_builder.rb, line 62 def type_for_token(token) case token when :command :table when :method_add_arg :trigger end end