Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

replaced delegation with forwardable

  • Loading branch information...
commit 44fa9371e33cc4a995dd7ecec22f0e5d6083a3cf 1 parent 07560b2
Anders Törnqvist authored
26 lib/resto/extra/delegation.rb
View
@@ -1,26 +0,0 @@
-# encoding: utf-8
-
-module Resto
- module Extra
- module Delegation
-
- def delegate(*methods)
- options = methods.pop
- to = options[:to]
- unless options.is_a?(Hash) && to
- raise ArgumentError, "Delegation needs a target. Supply an options
- hash with a :to key as the last argument
- (e.g. delegate :hello, :to => :greeter)."
- end
-
- methods.each do |method|
- class_eval <<-EOS
- def #{method}(*args, &block)
- #{to}.__send__(#{method.inspect}, *args, &block)
- end
- EOS
- end
- end
- end
- end
-end
10 lib/resto/request/base.rb
View
@@ -1,23 +1,23 @@
# encoding: utf-8
-require 'resto/extra/delegation'
+require 'forwardable'
+require 'resto/extra/copy'
require 'resto/request/uri'
require 'resto/request/header'
require 'resto/request/option'
require 'resto/request/factory'
require 'resto/translator/request_factory'
-require 'resto/extra/copy'
module Resto
module Request
class Base
- extend Resto::Extra::Delegation
+ extend Forwardable
include Resto::Request::Header
include Resto::Request::Uri
include Resto::Request::Option
- delegate :head, :head!, :get, :get!, :post, :post!,
- :put, :put!, :delete, :delete!, :to => :@request
+ def_delegators :@request, :head, :head!, :get, :get!, :post, :post!,
+ :put, :put!, :delete, :delete!
def initialize(request=Resto::Request::Factory)
@request_klass = request
10 lib/resto/request/factory.rb
View
@@ -1,16 +1,16 @@
# encoding: utf-8
require 'net/https'
-require 'resto/extra/delegation'
+require 'forwardable'
module Resto
module Request
class Factory
- extend Resto::Extra::Delegation
+ extend Forwardable
- delegate :read_host, :read_port, :options, :read_body, :composed_path,
- :composed_headers, :scheme, :use_ssl, :current_formatter,
- :to => :@request
+ def_delegators :@request, :read_host, :read_port, :options, :read_body,
+ :composed_path, :composed_headers, :scheme, :use_ssl,
+ :current_formatter
def initialize(request)
@request = request
Please sign in to comment.
Something went wrong with that request. Please try again.