Class: TestProf::AnyFixture::Dump::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/any_fixture/dump.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, adapter) ⇒ Subscriber

Returns a new instance of Subscriber.



43
44
45
46
47
48
# File 'lib/test_prof/any_fixture/dump.rb', line 43

def initialize(path, adapter)
  @path = path
  @adapter = adapter
  @tmp_path = path + ".tmp"
  @reset_pk = Set.new
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



41
42
43
# File 'lib/test_prof/any_fixture/dump.rb', line 41

def path
  @path
end

#tmp_pathObject (readonly)

Returns the value of attribute tmp_path.



41
42
43
# File 'lib/test_prof/any_fixture/dump.rb', line 41

def tmp_path
  @tmp_path
end

Instance Method Details

#commitObject



71
72
73
74
75
76
77
# File 'lib/test_prof/any_fixture/dump.rb', line 71

def commit
  return unless defined?(:@file)

  file.close

  FileUtils.mv(tmp_path, path)
end

#finish(_event, _id, payload) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/test_prof/any_fixture/dump.rb', line 60

def finish(_event, _id, payload)
  sql = payload.fetch(:sql)
  return unless trackable_sql?(sql)

  sql = payload[:binds].any? ? adapter.compile_sql(sql, quoted(payload[:binds])) : +sql

  sql.tr!("\n", " ")

  file.write(sql + ";\n")
end

#start(_event, _id, payload) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/test_prof/any_fixture/dump.rb', line 50

def start(_event, _id, payload)
  sql = payload.fetch(:sql)
  return if sql.match?(ANY_FIXTURE_IGNORE_RXP)

  matches = sql.match(MODIFY_RXP)
  return unless matches

  reset_pk!(matches[2]) if /insert/i.match?(matches[1])
end