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.



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

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

Instance Attribute Details

#environmentsObject

Returns the value of attribute environments.



3
4
5
# File 'lib/hoth/service_module.rb', line 3

def environments
  @environments
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/hoth/service_module.rb', line 3

def name
  @name
end

Instance Method Details

#[](env_name) ⇒ Object



44
45
46
# File 'lib/hoth/service_module.rb', line 44

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

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

Raises:



33
34
35
36
37
38
39
40
41
42
# File 'lib/hoth/service_module.rb', line 33

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])
end

#env(*env_names, &block) ⇒ Object



27
28
29
30
31
# File 'lib/hoth/service_module.rb', line 27

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