module Protector::Adapters::Sequel::Dataset

Patches ‘Sequel::Dataset`

Public Instance Methods

can?(action, field=false) click to toggle source
# File lib/protector/adapters/sequel/dataset.rb, line 37
def can?(action, field=false)
  protector_meta.can?(action, field)
end
creatable?() click to toggle source
# File lib/protector/adapters/sequel/dataset.rb, line 33
def creatable?
  model.new.restrict!(protector_subject).creatable?
end
each_with_protector(*args, &block) click to toggle source

Substitutes ‘row_proc` with {Protector} and injects protection scope

# File lib/protector/adapters/sequel/dataset.rb, line 47
def each_with_protector(*args, &block)
  return each_without_protector(*args, &block) unless protector_subject?

  relation = protector_defend_graph(clone, protector_subject)
  relation = protector_meta.eval_scope_procs(relation) if protector_meta.scoped?

  relation.row_proc = Restrictor.new(protector_subject, relation.row_proc)
  relation.each_without_protector(*args, &block)
end
protector_defend_graph(relation, subject) click to toggle source

Injects protection scope for every joined graph association

# File lib/protector/adapters/sequel/dataset.rb, line 58
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
    meta  = model.protector_meta.evaluate(subject)

    relation = meta.eval_scope_procs(relation) if meta.scoped?
  end

  relation
end
protector_meta(subject=protector_subject) click to toggle source

Gets {Protector::DSL::Meta::Box} of this dataset

# File lib/protector/adapters/sequel/dataset.rb, line 42
def protector_meta(subject=protector_subject)
  model.protector_meta.evaluate(subject)
end