Providers are auto-guessed when adding services.
This commit is contained in:
parent
9e7921a803
commit
4eefe465f4
@ -70,6 +70,10 @@ begin
|
||||
service.consumes.each do |token|
|
||||
provider = providers[token.token]?
|
||||
|
||||
if provider.nil?
|
||||
provider = service.get_default_provider token.token
|
||||
end
|
||||
|
||||
if provider.nil?
|
||||
STDERR.puts "This service consumes a “#{token.token}” token, but you have not specified what other service is supposed to provide it."
|
||||
STDERR.puts "Use the `service add #{args[1]} #{token.token}=<provider>` syntax to specify it."
|
||||
|
@ -67,6 +67,12 @@ class Environment
|
||||
_def
|
||||
end
|
||||
|
||||
def get_provider(token)
|
||||
Service.all.find do |service|
|
||||
service.environment == self && service.provides? token
|
||||
end.try &.id
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{name} (#{type.to_s.downcase})"
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ class Service
|
||||
end
|
||||
|
||||
specs.sections.select(&.name.==("consumes")).each do |section|
|
||||
@providers[section.name] = section.content["from"].as_s
|
||||
@providers[section.options[0]] = section.content["from"].as_s
|
||||
end
|
||||
end
|
||||
|
||||
@ -103,6 +103,12 @@ class Service
|
||||
@reference.consumes
|
||||
end
|
||||
|
||||
def provides?(token)
|
||||
provides.any? do |provider|
|
||||
provider.token == token
|
||||
end
|
||||
end
|
||||
|
||||
private def build_environment
|
||||
env = {} of String => String
|
||||
|
||||
@ -369,6 +375,10 @@ class Service
|
||||
|
||||
tree
|
||||
end
|
||||
|
||||
def get_default_provider(token) : String?
|
||||
@environment.get_provider(token) || Environment.root.get_provider(token)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user