Skip to content

Instantly share code, notes, and snippets.

@Heath101
Last active January 7, 2016 18:57
Show Gist options
  • Save Heath101/44ef3a9557fc2eb15a8f to your computer and use it in GitHub Desktop.
Save Heath101/44ef3a9557fc2eb15a8f to your computer and use it in GitHub Desktop.
Middlewares example
class SalesForce
def initialize(app)
@app = app
end
def call(env)
puts "SalesForce Handler"
puts "SalesForce AXID found"
env[:axids] << "AXID01234567890"
env[:salesforce] = {customer: {}}
@app.call(env)
end
end
class Zuora
def initialize(app)
@app = app
end
def call(env)
puts "Zuora Handler"
env[:zuora] = {}
@app.call(env)
end
end
class NicodemusSubscriptions
def initialize(app)
@app = app
end
def call(env)
puts "NicodemusSubscriptions Handler"
env[:nicodemus_subscriptions] = {}
@app.call(env)
end
end
class B2Church
def initialize(app)
@app = app
end
def call(env)
puts "B2Church Handler"
env[:b2church] = {relevant_data: "Foo"}
@app.call(env)
end
end
stack = Middleware::Builder.new do |d|
d.use SalesForce
d.use Zuora
d.use B2Church
d.use NicodemusSubscriptions
end
stack.call({emails: ["[email protected]"], axids: []})
# Outputs this:
#=> SalesForce Handler
#=> SalesForce AXID found
#=> Zuora Handler
#=> B2Church Handler
#=> NicodemusSubscriptions Handler
#=> => {:emails=>["[email protected]"],
#=> :axids=>["AXID01234567890"],
#=> :salesforce=>{:customer=>{}},
#=> :zuora=>{},
#=> :b2church=>{:relevant_data=>"Foo"},
#=> :nicodemus_subscriptions=>{}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment