Module: Arsi

Defined in:
lib/arsi.rb,
lib/arsi/version.rb,
lib/arsi/relation.rb,
lib/arsi/mysql2_adapter.rb,
lib/arsi/arel_tree_manager.rb

Defined Under Namespace

Modules: ArelTreeManager, Mysql2Adapter, Relation Classes: UnscopedSQL

Constant Summary collapse

VERSION =
'1.1.0'
ID_MATCH =
"(gu|uu|u)?id"
SCOPEABLE_REGEX =
/(^|_)#{ID_MATCH}$/i
SQL_MATCHER =
/[\s_`(]#{ID_MATCH}`?\s+(=|<>|IN|IS)/i
DEFAULT_CALLBACK =
lambda do |sql, relation|
  raise UnscopedSQL, "Missing ID in the where sql:\n#{sql}\nAdd id or use without_arsi"
end

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledObject (readonly)

Returns the value of attribute enabled.



25
26
27
# File 'lib/arsi.rb', line 25

def enabled
  @enabled
end

.violation_callbackObject

Returns the value of attribute violation_callback.



26
27
28
# File 'lib/arsi.rb', line 26

def violation_callback
  @violation_callback
end

Class Method Details

.arel_check!(arel, relation) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/arsi.rb', line 28

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) ⇒ Object



45
46
47
# File 'lib/arsi.rb', line 45

def disable(&block)
  run_with_arsi(false, &block)
end

.disable!Object



37
38
39
# File 'lib/arsi.rb', line 37

def disable!
  @enabled = false
end

.enable(&block) ⇒ Object



49
50
51
# File 'lib/arsi.rb', line 49

def enable(&block)
  run_with_arsi(true, &block)
end

.enable!Object



41
42
43
# File 'lib/arsi.rb', line 41

def enable!
  @enabled = true
end