Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed Jan 11, 2022
1 parent d509b33 commit 551bd25
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/dry/system/container.rb
Expand Up @@ -238,7 +238,7 @@ def import(other)
# @return [self]
#
# @api public
def register_provider(name, namespace: nil, from: nil, source: nil, &block)
def register_provider(name, namespace: nil, from: nil, source: nil, &block) # rubocop:disable Metrics/PerceivedComplexity
raise ProviderAlreadyRegisteredError, name if providers.key?(name)

if from && source.is_a?(Class)
Expand Down
16 changes: 10 additions & 6 deletions lib/dry/system/provider.rb
Expand Up @@ -64,7 +64,7 @@ def self.source_class(name:, group: nil, &block)
# @return [Symbol,String] default namespace for the container keys
attr_reader :namespace

attr_reader :container
attr_reader :provider_container

# Returns the main container used by this provider
#
Expand All @@ -81,10 +81,14 @@ def initialize(name:, namespace: nil, target_container:, source_class: nil, &blo
@namespace = namespace
@target_container = target_container

@container = build_container
@provider_container = build_provider_container
@statuses = []

@source = source_class.new(provider_container: container, target_container: target_container, &block)
@source = source_class.new(
provider_container: provider_container,
target_container: target_container,
&block
)
end

# Execute `prepare` step
Expand Down Expand Up @@ -145,7 +149,7 @@ def stopped?
# @return [Dry::Container]
#
# @api private
def build_container
def build_provider_container
container = Dry::Container.new

case namespace
Expand All @@ -157,7 +161,7 @@ def build_container
container
else
raise ArgumentError,
"+namespace:+ must be true, string or symbol: #{namespace.inspect} given."
"+namespace:+ must be true, string or symbol: #{namespace.inspect} given."
end
end

Expand All @@ -184,7 +188,7 @@ def run_step(step_name)
#
# @api private
def apply
container.each do |key, item|
provider_container.each do |key, item|
target_container.register(key, item) unless target_container.registered?(key)
end

Expand Down
19 changes: 9 additions & 10 deletions lib/dry/system/provider/source.rb
Expand Up @@ -46,10 +46,10 @@ def for(name:, group: nil, &block)

# @api private
def name
source = "#{source_name}"
source = "#{source_group}->#{source}" if source_group
source_str = source_name
source_str = "#{source_group}->#{source_str}" if source_group

"Dry::System::Provider::Source[#{source}]"
"Dry::System::Provider::Source[#{source_str}]"
end

# @api private
Expand Down Expand Up @@ -118,7 +118,9 @@ def initialize(provider_container:, target_container:, &block)
#
# @api private
def inspect
ivars = instance_variables.map { |ivar| "#{ivar}=#{instance_variable_get(ivar).inspect}"}.join(" ")
ivars = instance_variables.map { |ivar|
"#{ivar}=#{instance_variable_get(ivar).inspect}"
}.join(" ")

"#<#{self.class.name} #{ivars}>"
end
Expand All @@ -133,8 +135,7 @@ def inspect
# @see SourceDSL#prepare
#
# @api public
def prepare
end
def prepare; end

# Runs the behavior for the "start" lifecycle step.
#
Expand All @@ -148,8 +149,7 @@ def prepare
# @see SourceDSL#start
#
# @api public
def start
end
def start; end

# Runs the behavior for the "stop" lifecycle step.
#
Expand All @@ -164,8 +164,7 @@ def start
# @see SourceDSL#stop
#
# @api public
def stop
end
def stop; end

# Starts the providers registered with the given names.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/system/provider_registrar.rb
Expand Up @@ -88,7 +88,7 @@ def start_provider_dependency(component)
#
# @return [Array<Pathname>]
# @api public
def provider_files
def provider_files # rubocop:disable Layout/LineLength
@provider_files ||= provider_paths.each_with_object([[], []]) { |path, (provider_files, loaded)|
files = Dir["#{path}/#{RB_GLOB}"].sort

Expand Down

0 comments on commit 551bd25

Please sign in to comment.