Module: Protector::Adapters::Sequel::Dataset
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/protector/adapters/sequel/dataset.rb
Overview
Patches Sequel::Dataset
Defined Under Namespace
Classes: Restrictor
Instance Method Summary collapse
-
#each_with_protector(*args, &block) ⇒ Object
Substitutes
row_procwith Protector and injects protection scope. -
#protector_defend_graph(relation, subject) ⇒ Object
Injects protection scope for every joined graph association.
-
#protector_meta ⇒ Object
Gets DSL::Meta::Box of this dataset.
Instance Method Details
#each_with_protector(*args, &block) ⇒ Object
Substitutes row_proc with Protector and injects protection scope
39 40 41 42 43 44 45 46 47 |
# File 'lib/protector/adapters/sequel/dataset.rb', line 39 def each_with_protector(*args, &block) return each_without_protector(*args, &block) if !@protector_subject relation = protector_defend_graph(clone, @protector_subject) relation = relation.instance_eval(&.scope_proc) if .scoped? relation.row_proc = Restrictor.new(@protector_subject, relation.row_proc) relation.each_without_protector(*args, &block) end |
#protector_defend_graph(relation, subject) ⇒ Object
Injects protection scope for every joined graph association
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/protector/adapters/sequel/dataset.rb', line 50 def protector_defend_graph(relation, subject) return relation unless @opts[:eager_graph] @opts[:eager_graph][:reflections].each do |association, reflection| model = reflection[:cache][:class] if reflection[:cache].is_a?(Hash) && reflection[:cache][:class] model = reflection[:class_name].constantize unless model = model..evaluate(model, subject) relation = relation.instance_eval(&.scope_proc) if .scoped? end relation end |
#protector_meta ⇒ Object
Gets DSL::Meta::Box of this dataset
34 35 36 |
# File 'lib/protector/adapters/sequel/dataset.rb', line 34 def model..evaluate(model, @protector_subject) end |