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



249
250
251
252
253
254
255
# File 'lib/protector/dsl.rb', line 249

def protector_subject
  unless protector_subject?
    raise "Unprotected entity detected: use `restrict` method to protect it."
  end

  @protector_subject
end

#protector_subject?Boolean

Checks if model was restricted

Returns:

  • (Boolean)


274
275
276
# File 'lib/protector/dsl.rb', line 274

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



260
261
262
263
264
# File 'lib/protector/dsl.rb', line 260

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

#unrestrict!Object

Clears restriction subject



267
268
269
270
271
# File 'lib/protector/dsl.rb', line 267

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