Skip to content

Commit

Permalink
Cleanup Kirk::Client::Request
Browse files Browse the repository at this point in the history
  • Loading branch information
carllerche committed Feb 23, 2011
1 parent c150168 commit ae583b4
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/kirk/client/request.rb
Expand Up @@ -5,27 +5,27 @@ class Request
attr_reader :group

def initialize(group, method = nil, url = nil, handler = nil, body = nil, headers = {})
@group = group
method(method)
url(url)
handler(handler)
body(body)
headers(headers)

yield(self) if block_given?
@group = group
@url = url
@handler = handler
@body = body
@headers = headers
@method = normalize_method(method)

yield self if block_given?
end

%w/url headers handler body/.each do |method|
class_eval <<-RUBY
def #{method}(#{method} = nil)
@#{method} = #{method} if #{method}
def #{method}(*args)
@#{method} = args.first unless args.empty?
@#{method}
end
RUBY
end

def method(method = nil)
@method = method.to_s.upcase if method
def method(*args)
@method = normalize_method(args.first) unless args.empty?
@method
end

Expand All @@ -38,5 +38,11 @@ def validate!
raise InvalidRequestError, "Must specify a URL for the request"
end
end

private

def normalize_method(method)
method.to_s.upcase if method
end
end
end

0 comments on commit ae583b4

Please sign in to comment.