Module: Protector::DSL::Base

Extended by:
ActiveSupport::Concern
Defined in:
lib/protector/dsl.rb

Instance Method Summary collapse

Instance Method Details

#protector_subjectObject

Property accessor that makes sure you don't use subject on a non-protected model



289
290
291
292
293
294
295
# File 'lib/protector/dsl.rb', line 289

def protector_subject
  unless protector_subject?
    fail "Unprotected entity detected for '#{self.class}': use `restrict` method to protect it."
  end

  @protector_subject
end

#protector_subject?Boolean

Checks if model was restricted

Returns:

  • (Boolean)


314
315
316
# File 'lib/protector/dsl.rb', line 314

def protector_subject?
  @protector_subject_set == true && !Thread.current[:protector_disabled]
end

#restrict!(subject = nil) ⇒ Object

Assigns restriction subject

Parameters:

  • subject (Object) (defaults to: nil)

    Subject to restrict against



300
301
302
303
304
# File 'lib/protector/dsl.rb', line 300

def restrict!(subject=nil)
  @protector_subject = subject
  @protector_subject_set = true
  self
end

#unrestrict!Object

Clears restriction subject



307
308
309
310
311
# File 'lib/protector/dsl.rb', line 307

def unrestrict!
  @protector_subject = nil
  @protector_subject_set = false
  self
end