Module: Protector::Adapters::ActiveRecord::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/protector/adapters/active_record/base.rb
Overview
Patches ActiveRecord::Base
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #can?(action, field = false) ⇒ Boolean
-
#creatable? ⇒ Boolean
Checks if current model can be created in the context of current subject.
-
#destroyable? ⇒ Boolean
Checks if current model can be destroyed in the context of current subject.
-
#protector_changed ⇒ Object
Gathers real changed values bypassing restrictions.
-
#protector_meta(subject = protector_subject) ⇒ Object
Storage for DSL::Meta::Box.
-
#updatable? ⇒ Boolean
Checks if current model can be updated in the context of current subject.
-
#visible? ⇒ Boolean
Checks if current model can be selected in the context of current subject.
Instance Method Details
#can?(action, field = false) ⇒ Boolean
130 131 132 |
# File 'lib/protector/adapters/active_record/base.rb', line 130 def can?(action, field=false) .can?(action, field) end |
#creatable? ⇒ Boolean
Checks if current model can be created in the context of current subject
116 117 118 |
# File 'lib/protector/adapters/active_record/base.rb', line 116 def creatable? .creatable? protector_changed end |
#destroyable? ⇒ Boolean
Checks if current model can be destroyed in the context of current subject
126 127 128 |
# File 'lib/protector/adapters/active_record/base.rb', line 126 def destroyable? .destroyable? end |
#protector_changed ⇒ Object
Gathers real changed values bypassing restrictions
97 98 99 |
# File 'lib/protector/adapters/active_record/base.rb', line 97 def protector_changed HashWithIndifferentAccess[changed.map { |field| [field, read_attribute(field)] }] end |
#protector_meta(subject = protector_subject) ⇒ Object
Storage for DSL::Meta::Box
102 103 104 |
# File 'lib/protector/adapters/active_record/base.rb', line 102 def (subject=protector_subject) ||= self.class..evaluate(subject, self) end |
#updatable? ⇒ Boolean
Checks if current model can be updated in the context of current subject
121 122 123 |
# File 'lib/protector/adapters/active_record/base.rb', line 121 def updatable? .updatable? protector_changed end |
#visible? ⇒ Boolean
Checks if current model can be selected in the context of current subject
107 108 109 110 111 112 113 |
# File 'lib/protector/adapters/active_record/base.rb', line 107 def visible? return true unless .scoped? .relation.where( self.class.primary_key => id ).any? end |