Permalink
Browse files

fix bug when @response doesn't respond_to? :to_ary

  • Loading branch information...
1 parent 41216de commit 2aff1c0cbb070a3d65ccae5a54ddfba9c5d3a842 @phlipper phlipper committed Mar 30, 2012
Showing with 10 additions and 11 deletions.
  1. +10 −11 lib/rack/typekit.rb
View
@@ -1,28 +1,27 @@
-require 'rack'
-
module Rack #:nodoc:
class Typekit
-
+
VERSION = "0.1.0"
def initialize(app, options = {})
- raise ArgumentError, "Typekit Kit ID Required" unless options[:kit] and !options[:kit].empty?
+ raise ArgumentError, "Typekit Kit ID Required" unless options[:kit] &&
+ !options[:kit].empty?
@app, @options = app, options
end
- def call(env); dup._call(env); end
-
- def _call(env)
+ def call(env)
@status, @headers, @response = @app.call(env)
return [@status, @headers, @response] unless html?
response = Rack::Response.new([], @status, @headers)
- @response.each { |fragment| response.write inject(fragment) }
+ if @response.respond_to?(:to_ary)
+ @response.each { |fragment| response.write inject(fragment) }
+ end
response.finish
end
- private
+ private
- def html?; @headers['Content-Type'] =~ /html/; end
+ def html?; @headers["Content-Type"] =~ /html/; end
def inject(response)
script = <<-EOF
@@ -33,4 +32,4 @@ def inject(response)
response.gsub(%r{</head>}, script + "</head>")
end
end
-end
+end

0 comments on commit 2aff1c0

Please sign in to comment.