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.
- #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_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
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/protector/adapters/sequel/model.rb', line 80 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
94 95 96 97 |
# File 'lib/protector/adapters/sequel/model.rb', line 94 def _associated_dataset(*args) return super unless protector_subject? super.restrict!(protector_subject) end |
#_dataset(*args) ⇒ Object
This is used whenever we call counters and existance checkers
100 101 102 103 |
# File 'lib/protector/adapters/sequel/model.rb', line 100 def _dataset(*args) return super unless protector_subject? super.restrict!(protector_subject) end |
#before_destroy ⇒ Object
Destroy availability check
72 73 74 75 |
# File 'lib/protector/adapters/sequel/model.rb', line 72 def before_destroy return false if protector_subject? && !destroyable? super end |
#can?(action, field = false) ⇒ Boolean
59 60 61 |
# File 'lib/protector/adapters/sequel/model.rb', line 59 def can?(action, field=false) .can?(action, field) end |
#creatable? ⇒ Boolean
Checks if current model can be created in the context of current subject
43 44 45 46 |
# File 'lib/protector/adapters/sequel/model.rb', line 43 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
55 56 57 |
# File 'lib/protector/adapters/sequel/model.rb', line 55 def destroyable? .destroyable? end |
#protector_meta ⇒ Object
Storage for DSL::Meta::Box
26 27 28 29 30 31 32 33 34 |
# File 'lib/protector/adapters/sequel/model.rb', line 26 def ||= self.class..evaluate( Protector::Adapters::Sequel, self.class, protector_subject, self.class.columns, self ) end |
#updatable? ⇒ Boolean
Checks if current model can be updated in the context of current subject
49 50 51 52 |
# File 'lib/protector/adapters/sequel/model.rb', line 49 def updatable? fields = HashWithIndifferentAccess[changed_columns.map{|x| [x.to_s, @values[x]]}] .updatable?(fields) end |
#validate ⇒ Object
Basic security validations
64 65 66 67 68 69 |
# File 'lib/protector/adapters/sequel/model.rb', line 64 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
37 38 39 40 |
# File 'lib/protector/adapters/sequel/model.rb', line 37 def visible? return true unless .scoped? .relation.where(pk_hash).any? end |