module Arsi

Constants

DEFAULT_CALLBACK
ID_MATCH
SCOPEABLE_REGEX
SQL_MATCHER
VERSION

Attributes

enabled[R]
violation_callback[RW]

Public Class Methods

arel_check!(arel, relation) click to toggle source
# File lib/arsi.rb, line 33
def arel_check!(arel, relation)
  sql = arel.respond_to?(:ast) ? arel.where_sql : arel.to_s
  sql_check!(sql, relation)
end
disable(&block) click to toggle source
# File lib/arsi.rb, line 46
def disable(&block)
  run_with_arsi(false, &block)
end
disable!() click to toggle source
# File lib/arsi.rb, line 38
def disable!
  @enabled = false
end
enable(&block) click to toggle source
# File lib/arsi.rb, line 50
def enable(&block)
  run_with_arsi(true, &block)
end
enable!() click to toggle source
# File lib/arsi.rb, line 42
def enable!
  @enabled = true
end
sql_check!(sql, relation) click to toggle source
# File lib/arsi.rb, line 27
def sql_check!(sql, relation)
  return if !@enabled || relation.try(:without_arsi?)
  return if sql =~ SQL_MATCHER
  report_violation(sql, relation)
end

Private Class Methods

report_violation(sql, relation) click to toggle source
# File lib/arsi.rb, line 63
def report_violation(sql, relation)
  (violation_callback || DEFAULT_CALLBACK).call(sql, relation)
end
run_with_arsi(with_arsi) { || ... } click to toggle source
# File lib/arsi.rb, line 56
def run_with_arsi(with_arsi)
  previous, @enabled = @enabled, with_arsi
  yield
ensure
  @enabled = previous
end