class Protector::DSL::Meta

DSL meta storage and evaluator

Public Class Methods

new(adapter, model, &fields_proc) click to toggle source
# File lib/protector/dsl.rb, line 245
def initialize(adapter, model, &fields_proc)
  @adapter     = adapter
  @model       = model
  @fields_proc = fields_proc
end

Public Instance Methods

<<(block) click to toggle source

Register another protection block

# File lib/protector/dsl.rb, line 265
def <<(block)
  blocks << block
end
blocks() click to toggle source

Storage for ‘protect` blocks

# File lib/protector/dsl.rb, line 256
def blocks
  @blocks ||= []
end
blocks=(blocks) click to toggle source
# File lib/protector/dsl.rb, line 260
def blocks=(blocks)
  @blocks = blocks
end
evaluate(subject, entry=nil) click to toggle source

Calculate protection at the context of subject

@param subject [Object] Restriction subject @param entry [Object] An instance of the model

# File lib/protector/dsl.rb, line 279
def evaluate(subject, entry=nil)
  Box.new(@adapter, @model, fields, subject, entry, blocks)
end
fields() click to toggle source
# File lib/protector/dsl.rb, line 251
def fields
  @fields ||= @fields_proc.call
end
inherit(model, &fields_proc) click to toggle source
# File lib/protector/dsl.rb, line 269
def inherit(model, &fields_proc)
  clone = self.class.new(@adapter, model, &fields_proc)
  clone.blocks = @blocks.clone unless @blocks.nil?
  clone
end