Class: CaptureMigrationSql::SqlSubscriber
- Inherits:
-
ActiveSupport::Subscriber
- Object
- ActiveSupport::Subscriber
- CaptureMigrationSql::SqlSubscriber
- Defined in:
- lib/capture_migration_sql/sql_subscriber.rb
Constant Summary collapse
- IGNORE_PAYLOAD_NAMES =
["SCHEMA", "EXPLAIN"]
- SHOW_STATEMENT =
/\ASHOW\b/i- EXPLAIN_STATEMENT =
/\AEXPLAIN\b/i- SELECT_SCHEMA_MIGRATIONS =
/\ASELECT.*FROM.*schema_migrations/i- SELECT_INFORMATION_SCHEMA =
/\ASELECT.*information_schema/im- SQLLITE_VERSION =
/\ASELECT sqlite_version\(/i- IGNORE_STATEMENTS =
Regexp.union(SHOW_STATEMENT, EXPLAIN_STATEMENT, SELECT_SCHEMA_MIGRATIONS, SELECT_INFORMATION_SCHEMA, SQLLITE_VERSION)
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.attach_if_necessary ⇒ Object
19 20 21 22 23 24 |
# File 'lib/capture_migration_sql/sql_subscriber.rb', line 19 def attach_if_necessary unless defined?(@attached) && @attached attach_to(:active_record) @attached = true end end |
Instance Method Details
#sql(event) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/capture_migration_sql/sql_subscriber.rb', line 27 def sql(event) stream = CaptureMigrationSql.capture_stream return unless stream && CaptureMigrationSql.capture_enabled? payload = event.payload return if IGNORE_PAYLOAD_NAMES.include?(payload[:name]) sql = payload[:sql] return if sql.nil? || IGNORE_STATEMENTS.match(sql) sql = sql.strip sql = "#{sql};" unless sql.end_with?(";") stream.write("#{sql}\n\n") end |