Class: Protector::DSL::Meta

Inherits:
Object
  • Object
show all
Defined in:
lib/protector/dsl.rb

Overview

DSL meta storage and evaluator

Defined Under Namespace

Classes: Box

Instance Method Summary collapse

Instance Method Details

#<<(block) ⇒ Object

Register another protection block



191
192
193
# File 'lib/protector/dsl.rb', line 191

def <<(block)
  blocks << block
end

#blocksObject

Storage for protect blocks



186
187
188
# File 'lib/protector/dsl.rb', line 186

def blocks
  @blocks ||= []
end

#evaluate(model, subject, fields = [], entry = nil) ⇒ Object

Calculate protection at the context of subject

Parameters:

  • model (Class)

    The class of protected entity

  • subject (Object)

    Restriction subject

  • fields (Array<String>) (defaults to: [])

    All the fields the model has

  • entry (Object) (defaults to: nil)

    An instance of the model



201
202
203
204
205
# File 'lib/protector/dsl.rb', line 201

def evaluate(model, subject, fields=[], entry=nil)
  raise "Unprotected entity detected: use `restrict` method to protect it." unless subject

  Box.new(model, fields, subject, entry, blocks)
end