Grooming.

Fixes some issues introduced in the last commit.
master
Luka Vandervelden 2019-11-10 19:25:45 +01:00
parent d3fe317665
commit c43eb7af42
4 changed files with 9 additions and 16 deletions

View File

@ -366,9 +366,10 @@ if command.nil?
end
context = Service::Context.new
context.load
begin
context.load
args.shift
command.[2].call(context, args)
rescue e : Service::Exception

View File

@ -90,7 +90,7 @@ class Service::Context < Weird::Base
load_services
end
def get_service_by_id(id)
def get_service_by_id(id : String) : Service?
matches = id.match /[^\/]*/
unless matches # Should not happen, above regex would always match.
raise Exception.new "FIXME"
@ -102,7 +102,7 @@ class Service::Context < Weird::Base
end
end
def get_environment_by_name(name)
def get_environment_by_name(name : String) : Environment
_def = @environments.find &.name.==(name)
if _def.nil?
@ -131,7 +131,7 @@ class Service::Context < Weird::Base
port
end
def get_service_definition_by_name(name)
def get_service_definition_by_name(name : String) : ServiceDefinition
_def = @service_definitions.find &.name.==(name)
if _def.nil?

View File

@ -37,6 +37,8 @@ class Service
property domain : String?
getter ports = Hash(String, Int32).new
@reference : ServiceDefinition
# The place well store configuration and data.
@root : String?
@ -65,7 +67,7 @@ class Service
def initialize(@context : Context, name, environment_name : String?)
@providers = ProvidersList.new @context
@reference = ServiceDefinition.get name
@reference = context.get_service_definition_by_name name
@environment = if environment_name.nil? || environment_name == ""
@context.root_environment
else
@ -81,7 +83,7 @@ class Service
# name and their types were their name.
type = assignments["type"]?.try &.as_s
@name = (assignments["name"]?.try(&.as_s) || type).not_nil!
@reference = ServiceDefinition.get type || @name
@reference = context.get_service_definition_by_name (type || @name).not_nil!
@domain = assignments["domain"]?.try &.as_s

View File

@ -150,16 +150,6 @@ class ServiceDefinition
end
end
def self.get(name) : ServiceDefinition
_def = @@all.find &.name.==(name)
if _def.nil?
raise ::Service::Exception.new "Service '#{name}' does not exist."
end
_def
end
def to_s
name
end