Module: WADL::ResourceContainer

Included in:
Resource, Resources
Defined in:
lib/wadl/resource_container.rb

Overview

A mixin for objects that contain resources. If you include this, be sure to alias :find_resource to :find_resource_autogenerated beforehand.

Instance Method Summary collapse

Instance Method Details

#finalize_creationObject



47
48
49
50
51
52
# File 'lib/wadl/resource_container.rb', line 47

def finalize_creation
  resources.each { |r|
    define_singleton(r, :id,   :find_resource)
    define_singleton(r, :path, :find_resource_by_path)
  } if resources
end

#find_resource_by_path(path, auto_dereference = nil) ⇒ Object



42
43
44
45
# File 'lib/wadl/resource_container.rb', line 42

def find_resource_by_path(path, auto_dereference = nil)
  path = path.to_s
  find_resource(auto_dereference) { |r| r.path == path }
end

#resource(name_or_id) ⇒ Object



37
38
39
40
# File 'lib/wadl/resource_container.rb', line 37

def resource(name_or_id)
  name_or_id = name_or_id.to_s
  find_resource { |r| r.id == name_or_id || r.path == name_or_id }
end