Skip to content

Commit

Permalink
Create executor, which simply runs the operation
Browse files Browse the repository at this point in the history
  • Loading branch information
arsduo committed Sep 20, 2012
1 parent 0fa092b commit 7eb7b19
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/batch_api/processor/executor.rb
@@ -0,0 +1,18 @@
module BatchApi
class Processor
# Public: a simple middleware that lives at the end of the internal chain
# and simply executes each batch operation.
class Executor

# Public: initialize the middleware.
def initialize(app)
@app = app
end

# Public: execute the batch operation.
def call(env)
env[:op].execute
end
end
end
end
22 changes: 22 additions & 0 deletions spec/lib/processor/executor_spec.rb
@@ -0,0 +1,22 @@
require 'spec_helper'
require 'batch_api/processor/executor'

describe BatchApi::Processor::Executor do

let(:app) { stub("app", call: stub) }
let(:executor) { BatchApi::Processor::Executor.new(app) }
let(:result) { stub("result") }
let(:op) { stub("operation", execute: result) }
let(:env) { {op: op} }

describe "#call" do
it "executes the operation" do
op.should_receive(:execute)
executor.call(env)
end

it "returns the result" do
executor.call(env).should == result
end
end
end
File renamed without changes.

0 comments on commit 7eb7b19

Please sign in to comment.