Sha256: 6090036ba15b4aa7e12c98ad334539bb7e3b5ee7bc9d9f0f1376dac8601ebc1d

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 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.map(&:to_sym).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

1 entries across 1 versions & 1 rubygems

Version Path
activeresource-response-0.2.0 lib/activeresource-response/response_method.rb