Permalink
Browse files

use methods on the request object to implement `fetch`

Now the Headers internals don't depend on the env hash.
  • Loading branch information...
tenderlove committed Aug 21, 2015
1 parent c0c7268 commit bce4ff70dd1ab88e5b573ad8c88408f100cf219e
Showing with 8 additions and 2 deletions.
  1. +8 −2 actionpack/lib/action_dispatch/http/headers.rb
@@ -54,15 +54,21 @@ def key?(key)
end
alias :include? :key?
DEFAULT = Object.new # :nodoc:
# Returns the value for the given key mapped to @env.
#
# If the key is not found and an optional code block is not provided,
# raises a <tt>KeyError</tt> exception.
#
# If the code block is provided, then it will be run and
# its result returned.
def fetch(key, *args, &block)
env.fetch env_name(key), *args, &block
def fetch(key, default = DEFAULT)
@req.get_header(env_name(key)) do
return default unless default == DEFAULT
return yield if block_given?
raise NameError, key
end
end
def each(&block)

0 comments on commit bce4ff7

Please sign in to comment.