This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def behaves_like?(object) | |
expected_methods = | |
if object.respond_to?(:instance_methods) | |
object.instance_methods | |
else | |
object.methods | |
end | |
(expected_methods - methods).empty? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './basic_auth' | |
App = lambda do |env| | |
[200, { "Content-Type" => "text/html" }, ["Hello, Rack world!"]] | |
end | |
use BasicAuth, user_name: 'test:user', password: 'pass' | |
run App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base64' | |
class BasicAuth | |
def initialize(app, user_name:, password:) | |
@app = app | |
@user_name = user_name | |
@password = password | |
end | |
def call(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def transform_keys | |
return enum_for(:transform_keys) unless block_given? | |
result = self.class.new | |
each_key do |key| | |
result[yield(key)] = self[key] | |
end | |
result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/core_ext' | |
class Hash | |
unless method_defined?(:camelize_keys) | |
def camelize_keys(first_letter = :upper) | |
transform_keys { |key| key.camelize(first_letter) rescue key } | |
end | |
end | |
unless method_defined?(:camelize_keys!) |
NewerOlder