Sha256: d16b87a26841d7cb39f0441c50923c62593fc5ff41e4f43a49669be85aea0f41

Contents?: true

Size: 798 Bytes

Versions: 3

Compression:

Stored size: 798 Bytes

Contents

module InsalesApi
  class ActiveResourceProxy
    class << self
      def need_proxy?(value)
        klass = value.is_a?(Class) ? value : value.class
        return true if klass < Base || klass <= ActiveResource::Collection
        false
      end
    end

    def initialize(configurer, subject)
      @configurer = configurer
      @subject    = subject
    end

    def respond_to_missing?(method_name, include_private)
      @subject.respond_to?(method_name, include_private) || super
    end

    def method_missing(method_id, *args, &block)
      @configurer.init_api { proxy_for @subject.send(method_id, *args, &block) }
    end

    private
      def proxy_for(value)
        return value unless self.class.need_proxy?(value)
        self.class.new(@configurer, value)
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
insales_api-0.1.3 lib/insales_api/active_resource_proxy.rb
insales_api-0.1.2 lib/insales_api/active_resource_proxy.rb
insales_api-0.1.1 lib/insales_api/active_resource_proxy.rb