Module: Protector::Adapters::Sequel::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/protector/adapters/sequel/model.rb
Overview
Patches Sequel::Model
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#[](name) ⇒ Object
Security-checking attributes reader.
-
#_associated_dataset(*args) ⇒ Object
This is used whenever we fetch data.
-
#_dataset(*args) ⇒ Object
This is used whenever we call counters and existance checkers.
-
#before_destroy ⇒ Object
Destroy availability check.
-
#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_meta ⇒ Object
Storage for DSL::Meta::Box.
-
#updatable? ⇒ Boolean
Checks if current model can be updated in the context of current subject.
-
#validate ⇒ Object
Basic security validations.
-
#visible? ⇒ Boolean
Checks if current model can be selected in the context of current subject.
Instance Method Details
#[](name) ⇒ Object
Security-checking attributes reader
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/protector/adapters/sequel/model.rb', line 74 def [](name) if ( !@protector_subject || name == self.class.primary_key || (self.class.primary_key.is_a?(Array) && self.class.primary_key.include?(name)) || .readable?(name.to_s) ) @values[name] else nil end end |
#_associated_dataset(*args) ⇒ Object
This is used whenever we fetch data
88 89 90 |
# File 'lib/protector/adapters/sequel/model.rb', line 88 def _associated_dataset(*args) super.restrict!(@protector_subject) end |
#_dataset(*args) ⇒ Object
This is used whenever we call counters and existance checkers
93 94 95 |
# File 'lib/protector/adapters/sequel/model.rb', line 93 def _dataset(*args) super.restrict!(@protector_subject) end |
#before_destroy ⇒ Object
Destroy availability check
66 67 68 69 |
# File 'lib/protector/adapters/sequel/model.rb', line 66 def before_destroy return false if @protector_subject && !destroyable? super end |
#creatable? ⇒ Boolean
Checks if current model can be created in the context of current subject
41 42 43 44 |
# File 'lib/protector/adapters/sequel/model.rb', line 41 def creatable? fields = HashWithIndifferentAccess[keys.map{|x| [x.to_s, @values[x]]}] .creatable?(fields) end |
#destroyable? ⇒ Boolean
Checks if current model can be destroyed in the context of current subject
53 54 55 |
# File 'lib/protector/adapters/sequel/model.rb', line 53 def destroyable? .destroyable? end |
#protector_meta ⇒ Object
Storage for DSL::Meta::Box
26 27 28 29 30 31 32 33 |
# File 'lib/protector/adapters/sequel/model.rb', line 26 def @protector_meta ||= self.class..evaluate( self.class, @protector_subject, self.class.columns, self ) end |
#updatable? ⇒ Boolean
Checks if current model can be updated in the context of current subject
47 48 49 50 |
# File 'lib/protector/adapters/sequel/model.rb', line 47 def updatable? fields = HashWithIndifferentAccess[changed_columns.map{|x| [x.to_s, @values[x]]}] .updatable?(fields) end |
#validate ⇒ Object
Basic security validations
58 59 60 61 62 63 |
# File 'lib/protector/adapters/sequel/model.rb', line 58 def validate super return unless @protector_subject method = new? ? :creatable? : :updatable? errors.add(:base, I18n.t('protector.invalid')) unless __send__(method) end |
#visible? ⇒ Boolean
Checks if current model can be selected in the context of current subject
36 37 38 |
# File 'lib/protector/adapters/sequel/model.rb', line 36 def visible? .relation.where(pk_hash).any? end |