Class: Plumb::Decorator
- Inherits:
-
Object
- Object
- Plumb::Decorator
- Defined in:
- lib/plumb/decorator.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(block) ⇒ Decorator
constructor
A new instance of Decorator.
- #visit(type) ⇒ Composable
Constructor Details
#initialize(block) ⇒ Decorator
Returns a new instance of Decorator.
20 21 22 |
# File 'lib/plumb/decorator.rb', line 20 def initialize(block) @block = block end |
Class Method Details
.call(type, &block) ⇒ Object
16 17 18 |
# File 'lib/plumb/decorator.rb', line 16 def self.call(type, &block) new(block).visit(type) end |
Instance Method Details
#visit(type) ⇒ Composable
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/plumb/decorator.rb', line 26 def visit(type) type = case type when And left, right = visit_children(type) And.new(left, right) when Or left, right = visit_children(type) Or.new(left, right) when Not child = visit_children(type).first Not.new(child, errors: type.errors) when Policy child = visit_children(type).first Policy.new(type.policy_name, type.arg, child) else type end decorate(type) end |