Skip to content
Browse files

Moved Copy to directly under Resto namespace

  • Loading branch information...
1 parent ff906a0 commit b2c5f5fbe5da71b744a0aafd83d11b65eb717118 Anders Törnqvist committed Jun 10, 2011
Showing with 21 additions and 23 deletions.
  1. +2 −2 lib/resto.rb
  2. +15 −17 lib/resto/extra/copy.rb
  3. +1 −1 lib/resto/request/base.rb
  4. +3 −3 spec/resto/extra/copy_spec.rb
View
4 lib/resto.rb
@@ -180,15 +180,15 @@ def delete(id, request_path_options = {}, &block)
end
def request
- Extra::Copy.request_base(@request)
+ Copy.request_base(@request)
end
def response(response)
base_response.http_response(response)
end
def base_response
- Extra::Copy.response_base(@response)
+ Copy.response_base(@response)
end
def property_handler
View
32 lib/resto/extra/copy.rb
@@ -4,30 +4,28 @@
require 'resto/response/base'
module Resto
- module Extra
- module Copy
+ module Copy
- def self.request_base(request_base)
- Resto::Request::Base.new.tap do |copy|
- copy_instance_variables(request_base, copy, ["@request"])
+ def self.request_base(request_base)
+ Resto::Request::Base.new.tap do |copy|
+ copy_instance_variables(request_base, copy, ["@request"])
- request_klass = request_base.instance_variable_get("@request_klass")
- copy.instance_variable_set("@request", request_klass.new(copy))
- end
+ request_klass = request_base.instance_variable_get("@request_klass")
+ copy.instance_variable_set("@request", request_klass.new(copy))
end
+ end
- def self.response_base(response_base)
- Resto::Response::Base.new.tap do |copy|
- copy_instance_variables(response_base, copy, ["@response"])
- end
+ def self.response_base(response_base)
+ Resto::Response::Base.new.tap do |copy|
+ copy_instance_variables(response_base, copy, ["@response"])
end
+ end
- def self.copy_instance_variables(from, to, exclude = [])
- (from.instance_variables.map(&:to_s) - exclude).each do |name|
- instance_variable = from.instance_variable_get(name)
+ def self.copy_instance_variables(from, to, exclude = [])
+ (from.instance_variables.map(&:to_s) - exclude).each do |name|
+ instance_variable = from.instance_variable_get(name)
- to.instance_variable_set(name, instance_variable)
- end
+ to.instance_variable_set(name, instance_variable)
end
end
end
View
2 lib/resto/request/base.rb
@@ -31,7 +31,7 @@ def construct_path(options)
new_path.gsub!(/:#{substitute}/, options[substitute].to_s)
end
- Extra::Copy.request_base(self).path(new_path)
+ Copy.request_base(self).path(new_path)
end
def url(url)
View
6 spec/resto/extra/copy_spec.rb
@@ -2,15 +2,15 @@
require 'spec_helper'
require 'resto/extra/copy'
-describe Resto::Extra::Copy do
+describe Resto::Copy do
describe ".request_base" do
before do
@request_base = Resto::Request::Base.new.port(40).
url('http://www.aftonbladet.se:92/customers').
query('q=adam').
path('contacts')
- @new_request_base = Resto::Extra::Copy.request_base(@request_base).
+ @new_request_base = Resto::Copy.request_base(@request_base).
url('http://new.se:99/other').
query('q=not-same').
path('other-contacts/').
@@ -47,7 +47,7 @@
describe ".response_base" do
before do
@response_base = Resto::Response::Base.new.format(:json)
- @new_response_base = Resto::Extra::Copy.response_base(@response_base).
+ @new_response_base = Resto::Copy.response_base(@response_base).
http_response('response')
end

0 comments on commit b2c5f5f

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