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 30 def arel_check!(arel, relation) return unless @enabled return if relation && relation.without_arsi? # ::Arel::TreeManager, String, nil or ... ? sql = arel.respond_to?(:where_sql) ? arel_where_sql(arel, relation) : arel.to_s sql_check!(sql, relation) end
disable(&block)
click to toggle source
# File lib/arsi.rb, line 47 def disable(&block) run_with_arsi(false, &block) end
disable!()
click to toggle source
# File lib/arsi.rb, line 39 def disable! @enabled = false end
enable(&block)
click to toggle source
# File lib/arsi.rb, line 51 def enable(&block) run_with_arsi(true, &block) end
enable!()
click to toggle source
# File lib/arsi.rb, line 43 def enable! @enabled = true end
Private Class Methods
arel_where_sql(arel, relation)
click to toggle source
# File lib/arsi.rb, line 57 def arel_where_sql(arel, relation) if relation.nil? arel.where_sql else arel.where_sql(relation.model) end end
report_violation(sql, relation)
click to toggle source
# File lib/arsi.rb, line 77 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 70 def run_with_arsi(with_arsi) previous, @enabled = @enabled, with_arsi yield ensure @enabled = previous end
sql_check!(sql, relation)
click to toggle source
# File lib/arsi.rb, line 65 def sql_check!(sql, relation) return if SQL_MATCHER.match?(sql) report_violation(sql, relation) end