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_proc) ⇒ Meta

Returns a new instance of Meta.



245
246
247
248
249
# File 'lib/protector/dsl.rb', line 245

def initialize(adapter, model, &fields_proc)
  @adapter     = adapter
  @model       = model
  @fields_proc = fields_proc
end

Instance Method Details

#<<(block) ⇒ Object

Register another protection block



265
266
267
# File 'lib/protector/dsl.rb', line 265

def <<(block)
  blocks << block
end

#blocksObject

Storage for protect blocks



256
257
258
# File 'lib/protector/dsl.rb', line 256

def blocks
  @blocks ||= []
end

#blocks=(blocks) ⇒ Object



260
261
262
# File 'lib/protector/dsl.rb', line 260

def blocks=(blocks)
  @blocks = blocks
end

#evaluate(subject, entry = nil) ⇒ Object

Calculate protection at the context of subject

Parameters:

  • subject (Object)

    Restriction subject

  • entry (Object) (defaults to: nil)

    An instance of the model



279
280
281
# File 'lib/protector/dsl.rb', line 279

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

#fieldsObject



251
252
253
# File 'lib/protector/dsl.rb', line 251

def fields
  @fields ||= @fields_proc.call
end

#inherit(model, &fields_proc) ⇒ Object



269
270
271
272
273
# 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