Module: FatJam::ActsAsScopedModel::ClassMethods
- Defined in:
- lib/acts_as_revisable/acts/scoped_model.rb
Constant Summary collapse
- SCOPED_METHODS =
%w(construct_calculation_sql construct_finder_sql update_all delete_all destroy_all).freeze
Instance Method Summary collapse
- #acts_as_scoped_model(*args) ⇒ Object
- #call_method_with_static_scope(meth, args) ⇒ Object
- #disable_model_scope! ⇒ Object
- #enable_model_scope! ⇒ Object
- #scoped_model_enabled ⇒ Object
- #scoped_model_enabled=(value) ⇒ Object
- #scoped_model_enabled? ⇒ Boolean
- #without_model_scope ⇒ Object
Instance Method Details
#acts_as_scoped_model(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 63 def acts_as_scoped_model(*args) class << self attr_accessor :scoped_model_static_scope, :scoped_model_disable_count SCOPED_METHODS.each do |m| alias_method_chain m.to_sym, :static_scope end end self.scoped_model_disable_count = 0 self.scoped_model_static_scope = args. end |
#call_method_with_static_scope(meth, args) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 10 def call_method_with_static_scope(meth, args) return send(meth, *args) unless self.scoped_model_enabled? with_scope(self.scoped_model_static_scope) do send(meth, *args) end end |
#disable_model_scope! ⇒ Object
39 40 41 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 39 def disable_model_scope! self.scoped_model_disable_count += 1 end |
#enable_model_scope! ⇒ Object
43 44 45 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 43 def enable_model_scope! self.scoped_model_disable_count -= 1 end |
#scoped_model_enabled ⇒ Object
51 52 53 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 51 def scoped_model_enabled self.scoped_model_enabled? end |
#scoped_model_enabled=(value) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 55 def scoped_model_enabled=(value) if value == false disable_model_scope! else enable_model_scope! end end |
#scoped_model_enabled? ⇒ Boolean
47 48 49 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 47 def scoped_model_enabled? self.scoped_model_disable_count == 0 end |
#without_model_scope ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acts_as_revisable/acts/scoped_model.rb', line 26 def without_model_scope return unless block_given? begin self.scoped_model_enabled = false rv = yield ensure self.scoped_model_enabled = true end rv end |