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

Constructor Details

#initialize(adapter, model, fields) ⇒ Meta

Returns a new instance of Meta.



217
218
219
220
221
# File 'lib/protector/dsl.rb', line 217

def initialize(adapter, model, fields)
  @adapter = adapter
  @model   = model
  @fields  = fields
end

Instance Method Details

#<<(block) ⇒ Object

Register another protection block



229
230
231
# File 'lib/protector/dsl.rb', line 229

def <<(block)
  blocks << block
end

#blocksObject

Storage for protect blocks



224
225
226
# File 'lib/protector/dsl.rb', line 224

def blocks
  @blocks ||= []
end

#evaluate(subject, 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>)

    All the fields the model has

  • entry (Object) (defaults to: nil)

    An instance of the model



239
240
241
# File 'lib/protector/dsl.rb', line 239

def evaluate(subject, entry=nil)
  Box.new(@adapter, @model, @fields, subject, entry, blocks)
end