Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

replaced delegation with forwardable

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

0 comments on commit 44fa937

Please sign in to comment.
Something went wrong with that request. Please try again.