Skip to content

Commit

Permalink
Do manual hash key iteration to be 1.8 compatible
Browse files Browse the repository at this point in the history
Hash#select returns an array in 1.8, but a Hash in 1.9
  • Loading branch information
ajsharp committed Jan 7, 2011
1 parent 064e957 commit 8dd3318
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/papermill-agent/rack/collector.rb
Expand Up @@ -4,6 +4,7 @@ module Papermill
# The Collector class is the middleware component of papermill. # The Collector class is the middleware component of papermill.
# To use it with a rails app, you must add the following to # To use it with a rails app, you must add the following to
# your environment.rb file: # your environment.rb file:
#
# config.middleware.use Papermill::Collector # config.middleware.use Papermill::Collector
class Collector class Collector
def initialize(app) def initialize(app)
Expand Down
10 changes: 7 additions & 3 deletions lib/papermill-agent/response_adapters/base.rb
Expand Up @@ -30,11 +30,15 @@ def additional_response_data
end end


def extract_env_info 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 . # rename rack.* keys b/c mongo does not allow key names containing a .
rack_keys = ENV_CAPTURE_FIELDS.select { |key| key =~ /^rack\./ } naughty_rack_keys = ENV_CAPTURE_FIELDS.select { |key| key =~ /^rack\./ }
rack_keys.each do |key| naughty_rack_keys.each do |key|
new_key = key.gsub(/^rack\./, '').upcase new_key = key.gsub(/^rack\./, '').upcase
result_hash[new_key] = result_hash.delete(key) result_hash[new_key] = result_hash.delete(key)
end end
Expand Down

0 comments on commit 8dd3318

Please sign in to comment.