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



231
232
233
234
235
236
237
# File 'lib/protector/dsl.rb', line 231

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)


256
257
258
# File 'lib/protector/dsl.rb', line 256

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

#restrict!(subject) ⇒ Object

Assigns restriction subject

Parameters:

  • subject (Object)

    Subject to restrict against



242
243
244
245
246
# File 'lib/protector/dsl.rb', line 242

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

#unrestrict!Object

Clears restriction subject



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

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