Class: Hoth::ServiceModule

Inherits:
Object
  • Object
show all
Defined in:
lib/hoth/service_module.rb

Defined Under Namespace

Classes: Environment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ServiceModule

Returns a new instance of ServiceModule.



23
24
25
26
27
# File 'lib/hoth/service_module.rb', line 23

def initialize(attributes = {})
  @environments = {}
  @registered_services = []
  @name = attributes[:name]
end

Instance Attribute Details

#environmentsObject

Returns the value of attribute environments.



21
22
23
# File 'lib/hoth/service_module.rb', line 21

def environments
  @environments
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/hoth/service_module.rb', line 21

def name
  @name
end

#registered_servicesObject

Returns the value of attribute registered_services.



21
22
23
# File 'lib/hoth/service_module.rb', line 21

def registered_services
  @registered_services
end

Instance Method Details

#[](env_name) ⇒ Object



48
49
50
# File 'lib/hoth/service_module.rb', line 48

def [](env_name)
  @environments[env_name.to_sym]
end

#add_service(service_name, options = {}) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hoth/service_module.rb', line 35

def add_service(service_name, options = {})
  raise HothException.new("no endpoint-definition for environment '#{Hoth.env}' and service '#{service_name}'") unless self.environments[Hoth.env]

  service = ServiceRegistry.locate_service(service_name.to_sym)

  raise HothException.new("tried to add service '#{service_name}' but was not defined by service-definition") unless service
  
  service.module = self
  service.via_endpoint(options[:via])

  @registered_services << service
end

#env(*env_names, &block) ⇒ Object



29
30
31
32
33
# File 'lib/hoth/service_module.rb', line 29

def env(*env_names, &block)
  env_names.each do |env_name|
    @environments[env_name.to_sym] = Environment.new(&block)
  end
end