Class: Irumugam::ServiceRegistry

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServiceRegistry

Returns a new instance of ServiceRegistry.



7
8
9
10
# File 'lib/irumugam/service_registry.rb', line 7

def initialize
  @paths ||= {}
  @services ||= {}
end

Instance Attribute Details

#pathsObject

Returns the value of attribute paths.



5
6
7
# File 'lib/irumugam/service_registry.rb', line 5

def paths
  @paths
end

#servicesObject

Returns the value of attribute services.



5
6
7
# File 'lib/irumugam/service_registry.rb', line 5

def services
  @services
end

Class Method Details

.cleanup!Object



26
27
28
# File 'lib/irumugam/service_registry.rb', line 26

def self.cleanup!
  instance.cleanup!
end

.desc(name, &block) ⇒ Object



30
31
32
# File 'lib/irumugam/service_registry.rb', line 30

def self.desc(name,&block)
  instance.services[name] = Service.new(name, block)
end

.find(request) ⇒ Object



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

def self.find(request)
  instance.find(request)
end

Instance Method Details

#cleanup!Object



12
13
14
15
# File 'lib/irumugam/service_registry.rb', line 12

def cleanup!
  @paths = {}
  @services = {}
end

#find(request) ⇒ Object



17
18
19
20
# File 'lib/irumugam/service_registry.rb', line 17

def find(request)
  req_body = request.body.read
  paths.values.flatten.select { |c| c.matches?(request, req_body) }.first
end

#paths_for(service_name) ⇒ Object



22
23
24
# File 'lib/irumugam/service_registry.rb', line 22

def paths_for(service_name)
  paths.values.flatten.select { |c| c.service.name==service_name }
end