Module: Asana::Resources::Registry Private

Defined in:
lib/asana/resource_includes/registry.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Global registry of Resource subclasses. It provides lookup from singular and plural names to the actual class objects.

Examples:

class Unicorn < Asana::Resources::Resource
  path '/unicorns'
end
Registry.lookup(:unicorn) # => Unicorn
Registry.lookup_many(:unicorns) # => Unicorn

Class Method Summary collapse

Class Method Details

.lookup(singular_name) ⇒ Object

Looks up a resource class by its singular name.

Parameters:

  • singular_name (#to_s)

    the name of the resource, e.g :unicorn.

Returns:



36
37
38
39
40
# File 'lib/asana/resource_includes/registry.rb', line 36

def lookup(singular_name)
  resources.detect do |klass|
    klass.singular_name.to_s == singular_name.to_s
  end || Resource
end

.lookup_many(plural_name) ⇒ Object

Looks up a resource class by its plural name.

Parameters:

  • plural_name (#to_s)

    the plural name of the resource, e.g :unicorns.

Returns:



47
48
49
50
51
# File 'lib/asana/resource_includes/registry.rb', line 47

def lookup_many(plural_name)
  resources.detect do |klass|
    klass.plural_name.to_s == plural_name.to_s
  end || Resource
end

.register(resource_klass) ⇒ void

This method returns an undefined value.

Registers a new resource class.

Parameters:

  • resource_klass (Class)

    the resource class.



27
28
29
# File 'lib/asana/resource_includes/registry.rb', line 27

def register(resource_klass)
  resources << resource_klass
end

.resourcesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

this object is a mutable singleton, so it should not be accessed from multiple threads.

A set of Resource classes.

Returns:

  • the Set, defaulting to the empty set.



59
60
61
# File 'lib/asana/resource_includes/registry.rb', line 59

def resources
  @resources ||= Set.new
end