Sha256: dbb30ab461537975a8c2a59c59500fd951ae49324a5220709cf720971383f01f

Contents?: true

Size: 949 Bytes

Versions: 1

Compression:

Stored size: 949 Bytes

Contents

require 'activeresource'

module ActiveResource
  module CaptureHeaders
    module InstanceMethods
      private
      def request_with_headers(method, path, *arguments)
        request_without_headers(method, path, *arguments).tap do |resp|
          @headers = resp.to_hash
        end
      end

    end

    def self.included(receiver)
      receiver.class_eval do
        include InstanceMethods
        alias_method_chain :request, :headers
        attr :headers
      end
    end
  end
  
  module RetrieveHeaders
    module InstanceMethods
      def last_count
        @last_count ||= (c = connection.headers['x-query-count']) ? c[0].to_i : nil
      end
      
    end
    
    def self.included(receiver)
      receiver.class_eval do
        include InstanceMethods
      end
    end
  end
  
end

ActiveResource::Connection.send :include, ActiveResource::CaptureHeaders
ActiveResource::Base.send :include, ActiveResource::RetrieveHeaders

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zerigo_dns-1.0.5 lib/activeresource-ext.rb