activeresource-response 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/activeresource-response.rb +15 -13
- data/lib/activeresource-response/version.rb +1 -1
- metadata +1 -1
@@ -1,28 +1,30 @@
|
|
1
1
|
require "activeresource-response/version"
|
2
2
|
module ActiveresourceResponse
|
3
|
+
module Connection
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval <<-EOS
|
6
|
+
alias_method :origin_handle_response, :handle_response
|
7
|
+
attr_reader :http_response
|
8
|
+
def handle_response(response)
|
9
|
+
@http_response= response
|
10
|
+
origin_handle_response(response)
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
end
|
3
15
|
module AddResponseMethod
|
4
16
|
def self.included(base)
|
5
17
|
base.extend ClassMethods
|
6
18
|
end
|
7
19
|
module ClassMethods
|
8
|
-
def add_response_method(method_name = '
|
9
|
-
|
10
|
-
connection.class_eval <<-EOS
|
11
|
-
alias_method :origin_handle_response, :handle_response
|
12
|
-
attr_reader :#{method_name}
|
13
|
-
def handle_response(response)
|
14
|
-
@#{method_name}= response
|
15
|
-
origin_handle_response(response)
|
16
|
-
end
|
17
|
-
EOS
|
18
|
-
|
20
|
+
def add_response_method(method_name = 'http_response')
|
19
21
|
class_eval <<-EOS
|
20
22
|
class << self
|
21
23
|
alias_method :origin_find, :find
|
22
24
|
def find(*arguments)
|
23
25
|
result = origin_find(*arguments)
|
24
26
|
result.class_eval("attr_reader :#{method_name}")
|
25
|
-
result.instance_variable_set(:"@#{method_name}", connection
|
27
|
+
result.instance_variable_set(:"@#{method_name}", connection.http_response)
|
26
28
|
result
|
27
29
|
end
|
28
30
|
end
|
@@ -31,5 +33,5 @@ module ActiveresourceResponse
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
36
|
+
ActiveResource::Connection.send :include, ActiveresourceResponse::Connection
|
35
37
|
ActiveResource::Base.send :include, ActiveresourceResponse::AddResponseMethod
|