Skip to content

Commit

Permalink
Extract Chain::{DSL::Builder => ModuleBuilder}
Browse files Browse the repository at this point in the history
  • Loading branch information
snusnu committed Jul 31, 2013
1 parent e6373aa commit f253fd7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config/flay.yml
@@ -1,3 +1,3 @@
---
threshold: 11 # TODO see what flay thinks after Chain#{processors => definition}
total_score: 187
total_score: 190
2 changes: 1 addition & 1 deletion lib/substation.rb
Expand Up @@ -72,7 +72,7 @@ module Substation
require 'substation/chain'
require 'substation/chain/dsl'
require 'substation/chain/dsl/config'
require 'substation/chain/dsl/config/builder'
require 'substation/chain/dsl/module_builder'
require 'substation/chain/failure_data'
require 'substation/environment'
require 'substation/environment/dsl'
Expand Down
2 changes: 1 addition & 1 deletion lib/substation/chain/dsl.rb
Expand Up @@ -18,7 +18,7 @@ class DSL
#
# @api private
def self.build(registry, definition = Definition::EMPTY)
new(Config::Builder.call(registry), definition)
new(Config.build(registry), definition)
end

include Equalizer.new(:registry, :definition)
Expand Down
13 changes: 13 additions & 0 deletions lib/substation/chain/dsl/config.rb
Expand Up @@ -6,6 +6,19 @@ class DSL

# A configuration object used with a {DSL} instance
class Config

# Build a new config based on {registry} suitable for a {DSL} instance
#
# @param [Hash<Symbol, Processor::Builder>] registry
# the registry of processor builders used in an {Environment}
#
# @return [Config]
#
# @api private
def self.build(registry)
new(registry, ModuleBuilder.call(registry))
end

include Equalizer.new(:registry)

# The registry of processor builders
Expand Down
Expand Up @@ -3,31 +3,30 @@
module Substation
class Chain
class DSL
class Config

# Builds a {Config} suitable for a {DSL} instance
class Builder
# Builds a {Module} suitable for a {DSL} instance
class ModuleBuilder

# Builds a new {Config} instance targeted for a {DSL} instance
# Builds a new {Module} targeted for a {DSL} instance
#
# @param [Hash<Symbol, Processor::Builder>] registry
# the registry of processor builders used in an {Environment}
#
# @return [DSL]
# @return [Module]
#
# @api private
def self.call(registry)
new(registry).config
new(registry).dsl_module
end

include Adamantium::Flat

# Return a {Config} instance suitable for a {DSL} instance
# A module suitable for inclusion in a {DSL} instance
#
# @return [Config]
# @return [Module]
#
# @api private
attr_reader :config
attr_reader :dsl_module

# Initialize a new instance
#
Expand All @@ -40,7 +39,7 @@ def self.call(registry)
def initialize(registry)
@registry = registry
@dsl_module = Module.new
@config = Config.new(registry, compile_dsl_module)
initialize_dsl_module
end

private
Expand All @@ -50,13 +49,11 @@ def initialize(registry)
# @param [Hash<Symbol, Processor::Builder>] registry
# the registry of processor builders to define methods for
#
# @return [Module]
# a module with methods named after keys in +registry+
# @return [undefined]
#
# @api private
def compile_dsl_module
def initialize_dsl_module
@registry.each { |name, builder| define_dsl_method(name, builder) }
@dsl_module
end

# Define a new instance method on the +dsl+ module
Expand All @@ -81,8 +78,7 @@ def define_dsl_method(name, builder)
end
end

end # class Builder
end # class Config
end # class ModuleBuilder
end # class DSL
end # class Chain
end # module Substation

0 comments on commit f253fd7

Please sign in to comment.