Permalink
Browse files

Do manual hash key iteration to be 1.8 compatible

Hash#select returns an array in 1.8, but a Hash in 1.9
  • Loading branch information...
1 parent 064e957 commit 8dd3318ac7aaf300c25d20e00e5310013e5db535 @ajsharp committed Jan 7, 2011
Showing with 8 additions and 3 deletions.
  1. +1 −0 lib/papermill-agent/rack/collector.rb
  2. +7 −3 lib/papermill-agent/response_adapters/base.rb
@@ -4,6 +4,7 @@ module Papermill
# The Collector class is the middleware component of papermill.
# To use it with a rails app, you must add the following to
# your environment.rb file:
+ #
# config.middleware.use Papermill::Collector
class Collector
def initialize(app)
@@ -30,11 +30,15 @@ def additional_response_data
end
def extract_env_info
- result_hash = env.select { |key, value| ENV_CAPTURE_FIELDS.include?(key) }
+ result_hash = {}
+
+ # Hash#select returns an array in 1.8, so we have to do some manual
+ # iteration to extract the key/value pairs from the environment hash.
+ ENV_CAPTURE_FIELDS.each { |key| result_hash[key] = env[key] }
# rename rack.* keys b/c mongo does not allow key names containing a .
- rack_keys = ENV_CAPTURE_FIELDS.select { |key| key =~ /^rack\./ }
- rack_keys.each do |key|
+ naughty_rack_keys = ENV_CAPTURE_FIELDS.select { |key| key =~ /^rack\./ }
+ naughty_rack_keys.each do |key|
new_key = key.gsub(/^rack\./, '').upcase
result_hash[new_key] = result_hash.delete(key)
end

0 comments on commit 8dd3318

Please sign in to comment.