Class: Protector::DSL::Meta
- Inherits:
-
Object
- Object
- Protector::DSL::Meta
- Defined in:
- lib/protector/dsl.rb
Overview
DSL meta storage and evaluator
Defined Under Namespace
Classes: Box
Instance Method Summary collapse
-
#<<(block) ⇒ Object
Register another protection block.
-
#blocks ⇒ Object
Storage for
protect
blocks. - #blocks=(blocks) ⇒ Object
-
#evaluate(subject, entry = nil) ⇒ Object
Calculate protection at the context of subject.
- #fields ⇒ Object
- #inherit(model, &fields_proc) ⇒ Object
-
#initialize(adapter, model, &fields_proc) ⇒ Meta
constructor
A new instance of Meta.
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 |
#blocks ⇒ Object
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
279 280 281 |
# File 'lib/protector/dsl.rb', line 279 def evaluate(subject, entry=nil) Box.new(@adapter, @model, fields, subject, entry, blocks) end |
#fields ⇒ Object
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 |