Module: Resto::Copy
- Defined in:
- lib/resto/extra/copy.rb
Overview
Note:
This module is used internally by these classes/modules: Resto::ClassMethods (see method Resto::ClassMethods#request, and Resto::ClassMethods#base_response). Resto::Request::Base (see method Request::Base#construct_path).
This module has two helper methods that handles the process of copying the Request::Base object and Response::Base object correctly.
Class Method Summary collapse
- .copy_instance_variables(from, to, exclude = []) ⇒ Object
-
.request_base(request_base) ⇒ Request::Base
Returns a copy of the Request::Base object.
-
.response_base(response_base) ⇒ Response::Base
Returns a copy of the Response::Base object.
Class Method Details
.copy_instance_variables(from, to, exclude = []) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/resto/extra/copy.rb', line 51 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 end |
.request_base(request_base) ⇒ Request::Base
26 27 28 29 30 31 32 33 |
# File 'lib/resto/extra/copy.rb', line 26 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 end |
.response_base(response_base) ⇒ Response::Base
Returns a copy of the Response::Base object.
Examples:
Copy.response_base(response)
# => new_response
45 46 47 48 49 |
# File 'lib/resto/extra/copy.rb', line 45 def self.response_base(response_base) Resto::Response::Base.new.tap do |copy| copy_instance_variables(response_base, copy, ["@response"]) end end |