Sha256: f87e117d7ced36a28b99f2a23cecc6f069bb2819bc6468455124fad06e262d12

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

module Restfulie::Client#:nodoc

  module EntryPoint
    include HTTP::RequestMarshaller
    extend self

    @resources_configurations = {}
    def configuration_of(resource_name)
      @resources_configurations[resource_name]
    end

    def configuration_for(resource_name,configuration = Configuration.new)
      yield configuration if block_given?
      @resources_configurations[resource_name] = configuration
    end

    def retrieve(resource_name)
      returning Object.new do |resource| 
        restore.extend(Base)
        resource.configure
      end
    end

  end
  class NilEntryPoint
    include Restfulie::Client::EntryPoint
    # extend self
  end

  module Base
    include HTTP::RequestMarshaller
   
    def self.included(base)#:nodoc
      base.extend(self)
    end

    def uses_restfulie(configuration = Configuration.new,&block)
      EntryPoint.configuration_for(resource_name,configuration,&block)
      configure
    end

    def configure
      configuration = EntryPoint.configuration_of(resource_name)
      raise "Undefined configuration for #{resource_name}" unless configuration
      at(configuration.entry_point)
      configuration.representations.each do |representation_name,representation|
        register_representation(representation_name,representation)
      end
    end

    def resource_name
      @resource_name || @resource_name = self.class.to_s.to_sym 
    end

  end

end


# Shortcut to Restfulie::Client::EntryPoint
module Restfulie
  def self.at(uri)
    Client::NilEntryPoint.new.at(uri)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restfulie-0.7.2 lib/restfulie/client/base.rb
restfulie-0.7.1 lib/restfulie/client/base.rb