Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and power up failure chain (re)definition
- Loading branch information
Showing
33 changed files
with
317 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
--- | ||
threshold: 6 | ||
total_score: 100 | ||
total_score: 107 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
threshold: 19.5 | ||
threshold: 13.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,10 +70,7 @@ def compile_dsl | |
# @api private | ||
def define_dsl_method(name, processor, dsl) | ||
dsl.class_eval do | ||
define_method(name) do |*args, &block| | ||
failure_chain = self.class.build(processor[:block], block) | ||
use(processor[:class].new(failure_chain, *args)) | ||
end | ||
define_method(name) { |*args| use(processor.new(name, *args)) } | ||
end | ||
end | ||
|
||
|
@@ -101,41 +98,6 @@ def self.processors(chain, &block) | |
new(chain, &block).processors | ||
end | ||
|
||
# The substation environment used to build chains | ||
# | ||
# @return [Environment] | ||
# | ||
# @api private | ||
# attr_reader :env | ||
|
||
# Build a new chain based on all +blocks+ | ||
# | ||
# @param [Proc] *blocks | ||
# any number of blocks to instance_eval inside a new instance | ||
# | ||
# @return [Chain] | ||
# | ||
# @api private | ||
def self.build(*blocks) | ||
Chain.new(coerce(*blocks).processors) | ||
end | ||
|
||
# Coerce an array of blocks into a new instance | ||
# | ||
# @param [Proc] *blocks | ||
# any number of blocks to instance_eval inside the new instance | ||
# | ||
# @return [DSL] | ||
# | ||
# @api private | ||
def self.coerce(*blocks) | ||
blocks.compact.inject(new(EMPTY_ARRAY)) { |dsl, block| | ||
dsl.instance_eval(&block) | ||
} | ||
end | ||
|
||
private_class_method :coerce | ||
|
||
# Initialize a new instance | ||
# | ||
# @param [#each<#call>] processors | ||
|
@@ -179,6 +141,57 @@ def chain(other) | |
self | ||
end | ||
|
||
# Use +chain+ as the failure chain for the processor identified by +name+ | ||
# | ||
# @param [Symbol] name | ||
# the processor's name | ||
# | ||
# @param [#call] chain | ||
# the failure chain to use for the processor identified by +name+ | ||
# | ||
# @return [self] | ||
# | ||
# @api private | ||
def failure_chain(name, chain) | ||
replace_processor(processor(name), chain) | ||
self | ||
end | ||
|
||
private | ||
|
||
# Return the processor identified by +name+ | ||
# | ||
# @param [Symbol] name | ||
# the processor's name | ||
# | ||
# @return [#call] | ||
# the processor identified by +name+ | ||
# | ||
# @return [nil] | ||
# if no processor identified by +name+ is registered | ||
# | ||
# @api private | ||
def processor(name) | ||
processor = @processors.detect { |processor| processor.name == name } | ||
This comment has been minimized.
Sorry, something went wrong. |
||
unless processor | ||
raise UnknownProcessor, "No processor named #{name.inspect} is registered" | ||
end | ||
processor | ||
end | ||
|
||
# Replace +processor+'s failure chain with +chain+ | ||
# | ||
# @param [#call] processor | ||
# @param [#call] chain | ||
# | ||
# @return [undefined] | ||
# | ||
# @api private | ||
def replace_processor(processor, chain) | ||
index = @processors.index(processor) | ||
@processors.delete_at(index) | ||
@processors.insert(index, processor.with_failure_chain(chain)) | ||
This comment has been minimized.
Sorry, something went wrong.
dkubb
|
||
end | ||
end # class DSL | ||
end # class Chain | ||
end # module Substation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
What about: