 
 
 
-
-  resourcify: (constructor, resource_type) ->
+  resourcify: (constructor, resource_type, definition) ->
     client = @
     constructor ||= (@properties) ->
       @url = @properties.url

    @schema_manager = new SchemaManager(options.schemas...)
    @directory = options.directory
    @authorizer = options.authorizer
    @resources = {}

    @resource_definitions = options.resources

    @representation_ids = {}
    @resource_constructors = {}

    for id, schema of @schema_manager.ids
      if schema.type == "array"
        constructor = @array_wrapper(schema)
        @representation_ids[schema.id] = constructor
      else if schema.type == "object"
        constructor = @object_wrapper(schema)
        @representation_ids[schema.id] = constructor
      else if !SchemaManager.is_primitive(schema.type)
        constructor = @representation_constructor(schema)
        @representation_ids[schema.id] = constructor

    for resource_type, definition of @resource_definitions
      for id, constructor of @representation_ids
        # The assumption here is that the frag-ident part of a schema id
        # corresponds to the resource type.
        [base, name] = id.split("#")
        if name == resource_type
          @resourcify(constructor, resource_type)
          @resource_constructors[resource_type] = constructor

      # create a resource constructor for types with no directly associated schemas.
      @resource_constructors[resource_type] ||= @resourcify(null, resource_type)

    @create_resources(@directory)

  # Create resource instances using the URLs supplied in the service
  # description's directory.
  create_resources: (directory) ->
    for key, value of directory
      if @resource_constructors[key]
        @resources[key] = new @resource_constructors[key](url: value)

  array_wrapper: (schema) ->
    client = @

      schema.type

  wrap: (type, data) ->
    if wrapper = @representations[type]
      new wrapper(data)
    else
      data
