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:


34
35
36
37
38
# File 'lib/asana/resource_includes/registry.rb', line 34

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:


45
46
47
48
49
# File 'lib/asana/resource_includes/registry.rb', line 45

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.


25
26
27
# File 'lib/asana/resource_includes/registry.rb', line 25

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.


57
58
59
# File 'lib/asana/resource_includes/registry.rb', line 57

def resources
  @resources ||= Set.new
end