Class: OData::ServiceRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/odata/service_registry.rb

Overview

Provides a registry for keeping track of multiple OData::Service instances

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](lookup_key) ⇒ OData::Service?

Lookup a service by URL or name

Parameters:

  • lookup_key (String)

    the URL or name to lookup

Returns:



34
35
36
# File 'lib/odata/service_registry.rb', line 34

def self.[](lookup_key)
  OData::ServiceRegistry.instance[lookup_key]
end

.add(service) ⇒ Object

Add a service to the Registry

Parameters:



29
30
31
# File 'lib/odata/service_registry.rb', line 29

def self.add(service)
  OData::ServiceRegistry.instance.add(service)
end

Instance Method Details

#[](lookup_key) ⇒ OData::Service?

Lookup a service by URL or name

Parameters:

  • lookup_key (String)

    the URL or name to lookup

Returns:



22
23
24
25
26
# File 'lib/odata/service_registry.rb', line 22

def [](lookup_key)
  initialize_instance_variables
  index = @services_by_name[lookup_key] || @services_by_url[lookup_key]
  index.nil? ? nil : @services[index]
end

#add(service) ⇒ Object

Add a service to the Registry

Parameters:



11
12
13
14
15
16
# File 'lib/odata/service_registry.rb', line 11

def add(service)
  initialize_instance_variables
  @services << service if service.is_a?(OData::Service) && !@services.include?(service)
  @services_by_name[service.name] = @services.find_index(service)
  @services_by_url[service.service_url] = @services.find_index(service)
end