Module: ActiveRecord::NoTouching

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_record/no_touching.rb

Overview

Active Record No Touching

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applied_to?(klass) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


36
37
38
# File 'lib/active_record/no_touching.rb', line 36

def applied_to?(klass) #:nodoc:
  klasses.any? { |k| k >= klass }
end

.apply_to(klass) ⇒ Object

:nodoc:



29
30
31
32
33
34
# File 'lib/active_record/no_touching.rb', line 29

def apply_to(klass) #:nodoc:
  klasses.push(klass)
  yield
ensure
  klasses.pop
end

Instance Method Details

#no_touching?Boolean

Returns true if the class has no_touching set, false otherwise.

Project.no_touching do
  Project.first.no_touching? # true
  Message.first.no_touching? # false
end

Returns:

  • (Boolean)


53
54
55
# File 'lib/active_record/no_touching.rb', line 53

def no_touching?
  NoTouching.applied_to?(self.class)
end

#touchObject

:nodoc:



61
62
63
# File 'lib/active_record/no_touching.rb', line 61

def touch(*, **) # :nodoc:
  super unless no_touching?
end

#touch_laterObject

:nodoc:



57
58
59
# File 'lib/active_record/no_touching.rb', line 57

def touch_later(*, **) # :nodoc:
  super unless no_touching?
end