Class: Dynflow::Middleware::Register
- Inherits:
-
Object
- Object
- Dynflow::Middleware::Register
- Includes:
- Algebrick::TypeCheck
- Defined in:
- lib/dynflow/middleware/register.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize ⇒ Register
constructor
A new instance of Register.
- #merge!(register) ⇒ Object
- #use(middleware_class, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Register
Returns a new instance of Register.
7 8 9 10 11 12 13 |
# File 'lib/dynflow/middleware/register.rb', line 7 def initialize @rules = Hash.new do |h, k| h[k] = { before: [], after: [], replace: [] } end end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
5 6 7 |
# File 'lib/dynflow/middleware/register.rb', line 5 def rules @rules end |
Instance Method Details
#merge!(register) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/dynflow/middleware/register.rb', line 25 def merge!(register) Type! register, Middleware::Register register.rules.each do |klass, rules| use(klass, rules) end end |
#use(middleware_class, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/dynflow/middleware/register.rb', line 15 def use(middleware_class, = {}) = .keys - [:before, :after, :replace] if .any? raise ArgumentError, "Unexpected options: #{}" end @rules[middleware_class].merge!() do |key, old, new| old + Array(new) end end |