lib/happy/controller_ext/actions.rb in happy-0.1.0.pre.4 vs lib/happy/controller_ext/actions.rb in happy-0.1.0.pre.5
- old
+ new
@@ -71,16 +71,22 @@
def header(name, value)
name = name.to_s.dasherize.humanize if name.is_a?(Symbol)
response[name] = value
end
- def invoke(klass, options = {}, &blk)
- klass.new(env, options, &blk).perform
- end
-
- def run(app)
- context.response = app.call(request.env)
- halt!
+ def run(thing, options = {}, &blk)
+ if thing.is_a?(Class) && thing.ancestors.include?(Happy::Controller)
+ # Happy controllers!
+ thing.new(env, options, &blk).perform
+ elsif thing.respond_to?(:call)
+ # Rack apps!
+ context.response = thing.call(request.env)
+ halt!
+ elsif thing.respond_to?(:to_s)
+ thing.to_s
+ else
+ raise "Don't know how to run #{thing.inspect} :("
+ end
end
end
end
end