Class: Lapine::Consumer::Middleware::Registry
- Inherits:
-
Object
- Object
- Lapine::Consumer::Middleware::Registry
- Includes:
- Enumerable
- Defined in:
- lib/lapine/consumer/middleware.rb
Overview
Registry holds records of each middleware class that is added to the consumer middleware chain.
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #<<(klass_args) ⇒ Object
- #all ⇒ Object
- #delete(klass) ⇒ Object
- #each(&blk) ⇒ Object
- #index_of(klass) ⇒ Object
-
#initialize(registry = []) ⇒ Registry
constructor
A new instance of Registry.
- #insert(index, klass, args) ⇒ Object
Constructor Details
#initialize(registry = []) ⇒ Registry
Returns a new instance of Registry.
98 99 100 |
# File 'lib/lapine/consumer/middleware.rb', line 98 def initialize(registry = []) @registry = registry end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
96 97 98 |
# File 'lib/lapine/consumer/middleware.rb', line 96 def registry @registry end |
Instance Method Details
#<<(klass_args) ⇒ Object
114 115 116 |
# File 'lib/lapine/consumer/middleware.rb', line 114 def <<(klass_args) insert(-1, klass_args[0], klass_args[1]) end |
#all ⇒ Object
102 103 104 |
# File 'lib/lapine/consumer/middleware.rb', line 102 def all registry end |
#delete(klass) ⇒ Object
110 111 112 |
# File 'lib/lapine/consumer/middleware.rb', line 110 def delete(klass) registry.reject! { |register| register.klass == klass } end |
#each(&blk) ⇒ Object
106 107 108 |
# File 'lib/lapine/consumer/middleware.rb', line 106 def each(&blk) all.each(&blk) end |
#index_of(klass) ⇒ Object
118 119 120 |
# File 'lib/lapine/consumer/middleware.rb', line 118 def index_of(klass) registry.find_index { |register| register.klass == klass } end |
#insert(index, klass, args) ⇒ Object
122 123 124 125 |
# File 'lib/lapine/consumer/middleware.rb', line 122 def insert(index, klass, args) raise Lapine::DuplicateMiddleware if index_of(klass) registry.insert(index, Register.new(klass, args)) end |