Class: Arel::Middleware::DatabaseExecutor
- Inherits:
-
Object
- Object
- Arel::Middleware::DatabaseExecutor
- Defined in:
- lib/arel/middleware/database_executor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#final_block ⇒ Object
readonly
Returns the value of attribute final_block.
-
#index ⇒ Object
Returns the value of attribute index.
-
#middleware ⇒ Object
readonly
Returns the value of attribute middleware.
Instance Method Summary collapse
- #call(next_arel) ⇒ Object
-
#initialize(middleware) ⇒ DatabaseExecutor
constructor
A new instance of DatabaseExecutor.
- #run(arel, context, final_block) ⇒ Object
Constructor Details
#initialize(middleware) ⇒ DatabaseExecutor
Returns a new instance of DatabaseExecutor.
10 11 12 |
# File 'lib/arel/middleware/database_executor.rb', line 10 def initialize(middleware) @middleware = middleware end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/arel/middleware/database_executor.rb', line 7 def context @context end |
#final_block ⇒ Object (readonly)
Returns the value of attribute final_block.
8 9 10 |
# File 'lib/arel/middleware/database_executor.rb', line 8 def final_block @final_block end |
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'lib/arel/middleware/database_executor.rb', line 6 def index @index end |
#middleware ⇒ Object (readonly)
Returns the value of attribute middleware.
4 5 6 |
# File 'lib/arel/middleware/database_executor.rb', line 4 def middleware @middleware end |
Instance Method Details
#call(next_arel) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/arel/middleware/database_executor.rb', line 28 def call(next_arel) check_argument_type next_arel current_middleware = middleware[index] return execute_sql(next_arel) if current_middleware.nil? self.index += 1 case current_middleware.method(:call).arity when 2 current_middleware.call(next_arel, self) else current_middleware.call(next_arel, self, context.dup) end end |
#run(arel, context, final_block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/arel/middleware/database_executor.rb', line 14 def run(arel, context, final_block) @index = 0 @context = context @final_block = final_block result = call(arel) check_return_type result result ensure @index = 0 @context = nil @final_block = nil end |