Module: Arsi

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

Defined Under Namespace

Modules: ArelTreeManager, Mysql2Adapter, Persistence, Relation Classes: UnscopedSQL

Constant Summary collapse

VERSION =
'1.2.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.



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

def enabled
  @enabled
end

.violation_callbackObject

Returns the value of attribute violation_callback.



28
29
30
# File 'lib/arsi.rb', line 28

def violation_callback
  @violation_callback
end

Class Method Details

.arel_check!(arel, relation) ⇒ Object



30
31
32
33
34
35
36
37
# 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) ⇒ Object



47
48
49
# File 'lib/arsi.rb', line 47

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

.disable!Object



39
40
41
# File 'lib/arsi.rb', line 39

def disable!
  @enabled = false
end

.enable(&block) ⇒ Object



51
52
53
# File 'lib/arsi.rb', line 51

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

.enable!Object



43
44
45
# File 'lib/arsi.rb', line 43

def enable!
  @enabled = true
end