Sha256: cbea64bda0fd990712e855a0dee825b056b49b2233d0c3fd7fb2c6839e8acb22

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module ActiveresourceResponse   

  module ResponseMethod
    
    def self.included(base)
      base.extend ClassMethods
    end
    
    module ClassMethods
      def add_response_method(method_name = :http_response)

        remove_response_method  if methods.include?(:find_without_http_response)
        [:find, :get].each do |method| 
          instance_eval  <<-EOS
          alias #{method}_without_http_response #{method}
          def #{method}(*arguments)
            result = #{method}_without_http_response(*arguments)
            result.instance_variable_set(:@http_response, connection.http_response)
            def result.#{method_name} 
              @http_response
            end   
            result
          end
          EOS
        end
      end

      def remove_response_method
        [:find, :get].each do |method| 
          instance_eval   <<-EOS
            undef :#{method}
            alias :#{method} :#{method}_without_http_response 
            undef :#{method}_without_http_response
          EOS
                     
        end 
      end   

    end
  end   
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activeresource-response-0.1.0 lib/activeresource-response/response_method.rb
activeresource-response-0.0.9 lib/activeresource-response/response_method.rb
activeresource-response-0.0.8 lib/activeresource-response/response_method.rb
activeresource-response-0.0.7 lib/activeresource-response/response_method.rb