Module: ActiveResourceResponse::ResponseMethod::ClassMethods
- Defined in:
- lib/active_resource_response/response_method.rb
Instance Method Summary collapse
- #add_response_method(method_name = :http_response) ⇒ Object
- #http_response ⇒ Object
- #remove_response_method ⇒ Object
- #wrap_result(result) ⇒ Object
Instance Method Details
#add_response_method(method_name = :http_response) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_resource_response/response_method.rb', line 38 def add_response_method(method_name = :http_response) class_attribute :http_response_method self.http_response_method = method_name class << self alias :find_without_http_response :find def find(*arguments) result = find_without_http_response(*arguments) self.wrap_result(result) end end unless methods.include?(:find_without_http_response) end |
#http_response ⇒ Object
34 35 36 |
# File 'lib/active_resource_response/response_method.rb', line 34 def http_response connection.http_response end |
#remove_response_method ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/active_resource_response/response_method.rb', line 51 def remove_response_method class << self undef :find alias :find :find_without_http_response undef :find_without_http_response undef :http_response_method undef :http_response_method= end end |
#wrap_result(result) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/active_resource_response/response_method.rb', line 61 def wrap_result(result) result = SimpleDelegator.new(result) if result.frozen? result.instance_variable_set(:@http_response, connection.http_response) result.singleton_class.send(:define_method, self.http_response_method) do @http_response end result end |