Sha256: 6ad87224692e3a215823166efcc031007ac0e4aa1b9b68ed5768e62fbf265429

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

require 'rod/rest/exception'

module Rod
  module Rest
    class ProxyFactory
      # Creates new proxy factory based on the +metadata+ and using given web
      # +client+.
      # Options:
      # * proxy_class - the class used to create the resource proxy factories.
      def initialize(metadata,client,options={})
        proxy_class = options[:proxy_class] || Proxy
        @proxies = {}
        metadata.each do |resource_metadata|
          @proxies[resource_metadata.name] = proxy_class.new(resource_metadata,client)
        end
      end

      # Build new object-proxy from the hash-like +object_description+.
      def build(object_description)
        check_type(object_description[:type])
        @proxies[object_description[:type]].new(object_description)
      end

      private
      def check_type(type)
        raise UnknownResource.new(type) unless @proxies.has_key?(type)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rod-rest-0.0.1.1 lib/rod/rest/proxy_factory.rb
rod-rest-0.0.1 lib/rod/rest/proxy_factory.rb