Class: ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- Inherits:
-
Object
- Object
- ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- Defined in:
- lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb,
lib/convenient_service/support/middleware/stack_builder/entities/builders/rack/exceptions.rb
Defined Under Namespace
Modules: Exceptions
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #==(other) ⇒ Boolean?
-
#call(env) ⇒ Object
Can be any type.
- #clear ⇒ Boolean
- #delete(index_or_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack (also: #remove)
- #dup ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- #empty? ⇒ Boolean
- #has?(some_middleware) ⇒ Boolean
- #initialize(**kwargs) ⇒ void constructor
- #insert(index_or_middleware, other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack (also: #insert_before)
- #insert_after(index_or_middleware, other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- #insert_after_each(other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- #insert_before_each(other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- #replace(index_or_middleware, other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
- #to_a ⇒ Array
- #unshift(middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack (also: #prepend)
- #use(middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
Constructor Details
#initialize(**kwargs) ⇒ void
28 29 30 31 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 28 def initialize(**kwargs) @name = kwargs.fetch(:name) { "Stack" } @stack = kwargs.fetch(:stack) { [] } end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 22 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
16 17 18 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 16 def stack @stack end |
Instance Method Details
#==(other) ⇒ Boolean?
198 199 200 201 202 203 204 205 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 198 def ==(other) return unless other.instance_of?(self.class) return false if name != other.name return false if stack != other.stack true end |
#call(env) ⇒ Object
Returns Can be any type.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 70 def call(env) return env if stack.empty? run = stack[-1] app = stack[0..-2] .map { |middleware| proc { |app| middleware.new(app) } } .reverse .reduce(run) { |a, e| e[a] } app.call(env) end |
#clear ⇒ Boolean
51 52 53 54 55 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 51 def clear stack.clear self end |
#delete(index_or_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack Also known as: remove
181 182 183 184 185 186 187 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 181 def delete(index_or_middleware) index = cast_index(index_or_middleware) stack.delete_at(index) self end |
#dup ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
217 218 219 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 217 def dup self.class.new(name: name.dup, stack: stack.dup) end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 36 def empty? stack.empty? end |
#has?(some_middleware) ⇒ Boolean
44 45 46 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 44 def has?(some_middleware) stack.any? { |middleware| middleware == some_middleware } end |
#insert(index_or_middleware, other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack Also known as: insert_before
115 116 117 118 119 120 121 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 115 def insert(index_or_middleware, other_middleware) index = cast_index(index_or_middleware) stack.insert(index, other_middleware) self end |
#insert_after(index_or_middleware, other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
134 135 136 137 138 139 140 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 134 def insert_after(index_or_middleware, other_middleware) index = cast_index(index_or_middleware) stack.insert(index + 1, other_middleware) self end |
#insert_after_each(other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
156 157 158 159 160 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 156 def insert_after_each(other_middleware) @stack = stack.reduce([]) { |stack, middleware| stack.push(middleware, other_middleware) } self end |
#insert_before_each(other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
146 147 148 149 150 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 146 def insert_before_each(other_middleware) @stack = stack.reduce([]) { |stack, middleware| stack.push(other_middleware, middleware) } self end |
#replace(index_or_middleware, other_middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
168 169 170 171 172 173 174 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 168 def replace(index_or_middleware, other_middleware) index = cast_index(index_or_middleware) stack[index] = other_middleware self end |
#to_a ⇒ Array
210 211 212 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 210 def to_a stack end |
#unshift(middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack Also known as: prepend
88 89 90 91 92 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 88 def unshift(middleware) stack.unshift(middleware) self end |
#use(middleware) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::Rack
103 104 105 106 107 |
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/rack.rb', line 103 def use(middleware) stack << middleware self end |