action_logic 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +122 -0
- data/lib/action_logic.rb +2 -1
- data/lib/action_logic/action_benchmark.rb +8 -21
- data/lib/action_logic/action_benchmark/default_benchmark_block.rb +11 -0
- data/lib/action_logic/action_benchmark/default_formatter.rb +5 -5
- data/lib/action_logic/action_coordinator.rb +1 -1
- data/lib/action_logic/action_task.rb +1 -1
- data/lib/action_logic/action_use_case.rb +1 -1
- data/lib/action_logic/configuration.rb +44 -0
- data/lib/action_logic/version.rb +1 -1
- data/spec/action_logic/action_benchmark/default_formatter_spec.rb +6 -6
- data/spec/action_logic/action_coordinator_spec.rb +1 -1
- data/spec/action_logic/action_task_spec.rb +1 -1
- data/spec/action_logic/active_use_case_spec.rb +1 -1
- data/spec/action_logic/configuration_spec.rb +75 -0
- data/spec/spec_helper.rb +24 -1
- metadata +5 -4
- data/lib/action_logic/action_configuration.rb +0 -40
- data/spec/action_logic/action_configuration_spec.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c66d180782e1862be0377d7fe898882aa0ade055
|
4
|
+
data.tar.gz: 888830e3f75532ca8f4478d408a50c44598b0f06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a74659bc15c3f9d9269954cdf222f03bf33d10a0164ca11a76494e4d94ea508b8659d0c89f9fc344b374b56dd05de4b96e5377894f67644c0cc20a8530745cc2
|
7
|
+
data.tar.gz: 8178b2136a5c4855fb3f50318f97c1645f551d269e129b7b147d57a4c37919cd077edd9187c70bf85148969ae277d7e1e4d70b9e83db1b4356bbf50c78523509
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,11 @@ Why another business logic abstraction gem? `ActionLogic` provides teams of vari
|
|
32
32
|
* [Before Validations](#before-validations)
|
33
33
|
* [After Validations](#after-validations)
|
34
34
|
* [Around Validations](#around-validations)
|
35
|
+
* [Benchmarking](#benchmarking)
|
36
|
+
* [Enable Benchmarking](#enable-benchmarking)
|
37
|
+
* [Benchmark Logging](#benchmark-logging)
|
38
|
+
* [Benchark Log Formatting](#benchmark-log-formatting)
|
39
|
+
* [Custom Benchmark Handling](#custom-benchmark-handling)
|
35
40
|
|
36
41
|
### Backstory
|
37
42
|
|
@@ -925,3 +930,120 @@ result = ActionTaskExample.execute(:example_attribute => [1, 2, 3], :example_att
|
|
925
930
|
|
926
931
|
result # => #<ActionLogic::ActionContext example_attribute=[1, 2, 3], example_attribute2=1, status=:success>
|
927
932
|
```
|
933
|
+
|
934
|
+
### Benchmarking
|
935
|
+
|
936
|
+
At some point you may want to benchmark and profile the performance of your code. `ActionLogic` allows for benchmarking that
|
937
|
+
range from simple defaults to highly customizable options depending on your use case and needs.
|
938
|
+
|
939
|
+
### Enable Benchmarking
|
940
|
+
|
941
|
+
Because benchmarking negatively impacts performance, we must explicitly tell `ActionLogic` that we want to benchmark (otherwise
|
942
|
+
it defaults to ignore benchmarking). To do this, we configure `ActionLogic` using the `configure` method. With the provided
|
943
|
+
`config` object, we explicitly enable benchmarking by setting `config.benchmark = true`:
|
944
|
+
|
945
|
+
```ruby
|
946
|
+
ActionLogic.configure do |config|
|
947
|
+
config.benchmark = true
|
948
|
+
end
|
949
|
+
```
|
950
|
+
|
951
|
+
### Benchmark Logging
|
952
|
+
|
953
|
+
Additionally, `ActionLogic` writes a benchmark log to `$stdout` by default, or you can override this default configuration
|
954
|
+
by specifying a log file. To do this, you configure `ActionLogic` to use a `File` object for logging benchmark results via the
|
955
|
+
`ActionLogic.configure` method:
|
956
|
+
|
957
|
+
```ruby
|
958
|
+
ActionLogic.configure do |config|
|
959
|
+
config.benchmark = true
|
960
|
+
config.benchmark_log = File.open("benchmark.log", "w")
|
961
|
+
end
|
962
|
+
```
|
963
|
+
|
964
|
+
### Benchmark Log Formatting
|
965
|
+
|
966
|
+
By default, `ActionLogic` formats benchmark logs in the following format:
|
967
|
+
|
968
|
+
```
|
969
|
+
context:ValidateAroundPresenceTestUseCase user_time:0.000000 system_time:0.000000 total_time:0.000000 real_time:0.000135
|
970
|
+
...
|
971
|
+
```
|
972
|
+
|
973
|
+
The default format is intended to be machine readable for easy parsing and is not intended to be used for human reading.
|
974
|
+
However, if you wish to change the format of the log output, `ActionLogic` allows you to override the default formatter by
|
975
|
+
allowing you to provide your own formatter:
|
976
|
+
|
977
|
+
```ruby
|
978
|
+
ActionLogic.configure do |config|
|
979
|
+
config.benchmark = true
|
980
|
+
config.benchmark_log = File.open("benchmark.log", "w")
|
981
|
+
config.benchmark_formatter = YourCustomFormatter
|
982
|
+
end
|
983
|
+
```
|
984
|
+
|
985
|
+
Where `YourCustomFormatter` subclasses `ActionLogic::ActionBenchmark::DefaultFormatter`:
|
986
|
+
|
987
|
+
```ruby
|
988
|
+
class CustomFormatter < ActionLogic::ActionBenchmark::DefaultFormatter
|
989
|
+
|
990
|
+
def log_coordinator(benchmark_result, execution_context_name)
|
991
|
+
benchmark_log.puts("The ActionCoordinator #{execution_context_name} took #{benchmark_result.real} to complete.")
|
992
|
+
end
|
993
|
+
|
994
|
+
def log_use_case(benchmark_result, execution_context_name)
|
995
|
+
benchmark_log.puts("The ActionUseCase #{execution_context_name} took #{benchmark_result.real} to complete.")
|
996
|
+
end
|
997
|
+
|
998
|
+
def log_task(benchmark_result, execution_context_name)
|
999
|
+
benchmark_log.puts("The ActionTask #{execution_context_name} took #{benchmark_result.real} to complete.")
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
end
|
1003
|
+
```
|
1004
|
+
|
1005
|
+
From the example above, you can see that a custom formatter is required to define three methods: `log_coordinator`, `log_use_case` and `log_task`. The `log_t cqcoordinator`
|
1006
|
+
method is called when a `ActionCoordinator` context is benchmarked. The `use_case` and `task` methods are invoked when `ActionUseCase` and `ActionTask`
|
1007
|
+
contexts are benchmarked, respectively.
|
1008
|
+
|
1009
|
+
Each of the three log methods receives two input parameters: `benchmark_result` and `execution_context_name` where `benchmark_result` is a Ruby
|
1010
|
+
standard library `Benchmark` result object, and `execution_context_name` is the class name of the `ActionLogic` context.
|
1011
|
+
|
1012
|
+
Once configured, you can verify that the formatter outputs to the specified log file by executing your `ActionLogic` contexts
|
1013
|
+
and verifying that the log file is written to with the correct format:
|
1014
|
+
|
1015
|
+
```
|
1016
|
+
The ActionUseCase TestUseCase2 took 0.00011722202179953456 to complete.
|
1017
|
+
The ActionTask TestTask3 took 4.570698365569115e-05 to complete.
|
1018
|
+
...
|
1019
|
+
```
|
1020
|
+
|
1021
|
+
### Custom Benchmark Handling
|
1022
|
+
|
1023
|
+
By default, `ActionLogic` benchmarks execution contexts using Ruby's `Benchmark` module. If you are content with a `Benchmark` result object, then
|
1024
|
+
you do not need to specify a custom benchmark handler. However, if you wish to have maximum control, or you require something different than Ruby's
|
1025
|
+
`Benchmark` module, you can define a custom handler like so:
|
1026
|
+
|
1027
|
+
```ruby
|
1028
|
+
class CustomHandler
|
1029
|
+
def call
|
1030
|
+
# custom logic
|
1031
|
+
yield
|
1032
|
+
# custom logic
|
1033
|
+
end
|
1034
|
+
end
|
1035
|
+
```
|
1036
|
+
|
1037
|
+
Your custom handler is free to define any custom logic, but you must yield during the body of the `call` method. This is what triggers the execution
|
1038
|
+
context and will allow your custom handler to measure the length of execution. If you do not yield, the relevant `ActionCoordinator`, `ActionUseCase`
|
1039
|
+
or `ActionTask` will not be executed and will result in no execution to benchmark.
|
1040
|
+
|
1041
|
+
Additionally, you must register your custom handler with `ActionLogic` using `ActionLogic.configure`:
|
1042
|
+
|
1043
|
+
```ruby
|
1044
|
+
ActionLogic.configure do |config|
|
1045
|
+
config.benchmark = true
|
1046
|
+
config.benchmark_log = File.open("benchmark.log", "w")
|
1047
|
+
config.benchmark_handler = CustomHandler.new
|
1048
|
+
end
|
1049
|
+
```
|
data/lib/action_logic.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'action_logic/action_configuration'
|
2
1
|
require 'action_logic/action_context'
|
3
2
|
require 'action_logic/action_coordinator'
|
4
3
|
require 'action_logic/action_core'
|
@@ -7,6 +6,8 @@ require 'action_logic/action_use_case'
|
|
7
6
|
require 'action_logic/action_validation'
|
8
7
|
require 'action_logic/action_benchmark'
|
9
8
|
require 'action_logic/action_benchmark/default_formatter'
|
9
|
+
require 'action_logic/action_benchmark/default_benchmark_block'
|
10
10
|
|
11
|
+
require 'action_logic/configuration'
|
11
12
|
require 'action_logic/errors'
|
12
13
|
require 'action_logic/version'
|
@@ -1,38 +1,25 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
1
|
module ActionLogic
|
4
2
|
module ActionBenchmark
|
5
|
-
|
6
3
|
module ClassMethods
|
7
4
|
def with_benchmark(execution_context, &block)
|
8
|
-
|
9
|
-
benchmark_result, context = benchmark!(&block)
|
10
|
-
log!(benchmark_result, execution_context)
|
11
|
-
context
|
12
|
-
else
|
13
|
-
block.call
|
14
|
-
end
|
5
|
+
ActionLogic.benchmark? ? benchmark!(execution_context, &block) : block.call
|
15
6
|
end
|
16
7
|
|
17
8
|
private
|
18
9
|
|
19
|
-
def benchmark
|
20
|
-
ActionConfiguration.benchmark?
|
21
|
-
end
|
22
|
-
|
23
|
-
def benchmark!(&block)
|
10
|
+
def benchmark!(execution_context, &block)
|
24
11
|
context = nil
|
25
|
-
benchmark_result =
|
26
|
-
|
12
|
+
benchmark_result = ActionLogic.benchmark_handler.call { context = block.call }
|
13
|
+
log!(benchmark_result, execution_context)
|
14
|
+
context
|
27
15
|
end
|
28
16
|
|
29
17
|
def log!(benchmark_result, execution_context)
|
30
|
-
benchmark_formatter.send(execution_context.__private__type,
|
18
|
+
ActionLogic.benchmark_formatter.send("log_#{execution_context.__private__type}".to_sym,
|
19
|
+
benchmark_result,
|
20
|
+
execution_context.name)
|
31
21
|
end
|
32
22
|
|
33
|
-
def benchmark_formatter
|
34
|
-
ActionConfiguration.benchmark_formatter
|
35
|
-
end
|
36
23
|
end
|
37
24
|
end
|
38
25
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module ActionLogic
|
2
2
|
module ActionBenchmark
|
3
3
|
class DefaultFormatter
|
4
|
-
def initialize(benchmark_log:
|
4
|
+
def initialize(benchmark_log: ActionLogic.benchmark_log)
|
5
5
|
@benchmark_log = benchmark_log
|
6
6
|
end
|
7
7
|
|
8
8
|
def format(benchmark_result, context_name)
|
9
|
-
benchmark_log.printf("
|
9
|
+
benchmark_log.printf("%s%s %s%f %s%f %s%f %s%f\n",
|
10
10
|
"context:",
|
11
11
|
context_name,
|
12
12
|
"user_time:",
|
@@ -19,9 +19,9 @@ module ActionLogic
|
|
19
19
|
benchmark_result.real)
|
20
20
|
end
|
21
21
|
|
22
|
-
alias_method :
|
23
|
-
alias_method :
|
24
|
-
alias_method :
|
22
|
+
alias_method :log_coordinator, :format
|
23
|
+
alias_method :log_use_case, :format
|
24
|
+
alias_method :log_task, :format
|
25
25
|
|
26
26
|
private
|
27
27
|
attr_reader :benchmark_log
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module ActionLogic
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def self.configure(&block)
|
7
|
+
block.call(configuration_options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration_options
|
11
|
+
@configuration_options ||= OpenStruct.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.benchmark?
|
15
|
+
configuration_options.benchmark || false
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.benchmark_log
|
19
|
+
configuration_options.benchmark_log || $stdout
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.benchmark_formatter
|
23
|
+
custom_benchmark_formatter || default_formatter
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.benchmark_handler
|
27
|
+
configuration_options.benchmark_handler || ActionBenchmark::DefaultBenchmarkHandler.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.reset!
|
31
|
+
@configuration_options = OpenStruct.new
|
32
|
+
@custom_benchmark_formatter = nil
|
33
|
+
@default_formatter = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.custom_benchmark_formatter
|
37
|
+
@custom_benchmark_formatter ||= configuration_options.benchmark_formatter &&
|
38
|
+
configuration_options.benchmark_formatter.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.default_formatter
|
42
|
+
@default_formatter ||= ActionBenchmark::DefaultFormatter.new
|
43
|
+
end
|
44
|
+
end
|
data/lib/action_logic/version.rb
CHANGED
@@ -9,21 +9,21 @@ module ActionLogic::ActionBenchmark
|
|
9
9
|
subject { described_class.new(benchmark_log: benchmark_log) }
|
10
10
|
|
11
11
|
it "writes the benchmark result to the log for an ActionCoordinator" do
|
12
|
-
subject.
|
12
|
+
subject.log_coordinator(benchmark_result, "CoordinatorContext")
|
13
13
|
expect(benchmark_log.string).to\
|
14
|
-
eq "context:
|
14
|
+
eq "context:CoordinatorContext user_time:0.000030 system_time:0.000020 total_time:0.000010 real_time:0.000300\n"
|
15
15
|
end
|
16
16
|
|
17
17
|
it "writes the benchmark result to the log for an ActionUseCase" do
|
18
|
-
subject.
|
18
|
+
subject.log_use_case(benchmark_result, "UseCaseContext")
|
19
19
|
expect(benchmark_log.string).to\
|
20
|
-
eq "context:
|
20
|
+
eq "context:UseCaseContext user_time:0.000030 system_time:0.000020 total_time:0.000010 real_time:0.000300\n"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "writes the benchmark result to the log for an ActionTask" do
|
24
|
-
subject.
|
24
|
+
subject.log_task(benchmark_result, "TaskContext")
|
25
25
|
expect(benchmark_log.string).to\
|
26
|
-
eq "context:
|
26
|
+
eq "context:TaskContext user_time:0.000030 system_time:0.000020 total_time:0.000010 real_time:0.000300\n"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -6,7 +6,7 @@ require 'fixtures/custom_types'
|
|
6
6
|
module ActionLogic
|
7
7
|
describe ActionCoordinator do
|
8
8
|
it "knows its type" do
|
9
|
-
expect(TestCoordinator1.__private__type).to eq(
|
9
|
+
expect(TestCoordinator1.__private__type).to eq("coordinator")
|
10
10
|
end
|
11
11
|
|
12
12
|
context "no failures and no halts" do
|
@@ -6,7 +6,7 @@ require 'fixtures/custom_types'
|
|
6
6
|
module ActionLogic
|
7
7
|
describe ActionUseCase do
|
8
8
|
it "knows its type" do
|
9
|
-
expect(SimpleTestUseCase.__private__type).to eq(
|
9
|
+
expect(SimpleTestUseCase.__private__type).to eq("use_case")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns an instance of ActionContext" do
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_logic'
|
3
|
+
|
4
|
+
describe ActionLogic do
|
5
|
+
|
6
|
+
subject { described_class }
|
7
|
+
|
8
|
+
around do |example|
|
9
|
+
described_class.reset!
|
10
|
+
example.run
|
11
|
+
described_class.reset!
|
12
|
+
end
|
13
|
+
|
14
|
+
context "benchmark" do
|
15
|
+
it "defaults the benchmark configuration option to false" do
|
16
|
+
expect(described_class.benchmark?).to be_falsey
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns true when the benchmark configuration option is set to true" do
|
20
|
+
described_class.configure do |config|
|
21
|
+
config.benchmark = true
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(described_class.benchmark?).to be_truthy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "benchmark_log" do
|
29
|
+
it "defaults benchmark log file to stdout" do
|
30
|
+
expect(described_class.benchmark_log).to eq($stdout)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns the log file when the benchmark log configuration option is set" do
|
34
|
+
temp_file = Object.new
|
35
|
+
|
36
|
+
described_class.configure do |config|
|
37
|
+
config.benchmark_log = temp_file
|
38
|
+
end
|
39
|
+
|
40
|
+
expect(described_class.benchmark_log).to eq(temp_file)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "benchmark_formatter" do
|
45
|
+
it "uses default formatter if a custom formatter is not provided" do
|
46
|
+
expect(described_class.benchmark_formatter).to be_a(ActionLogic::ActionBenchmark::DefaultFormatter)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "uses a custom formatter if one is provided" do
|
50
|
+
class CustomFormatter; end
|
51
|
+
|
52
|
+
described_class.configure do |config|
|
53
|
+
config.benchmark_formatter = CustomFormatter
|
54
|
+
end
|
55
|
+
|
56
|
+
expect(described_class.benchmark_formatter).to be_a(CustomFormatter)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "benchmark_handler" do
|
61
|
+
it "uses a default benchmark handler if a custom benchmark handler is not provided" do
|
62
|
+
expect(described_class.benchmark_handler).to be_a(ActionLogic::ActionBenchmark::DefaultBenchmarkHandler)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "uses a custom benchmark handler if one is provided" do
|
66
|
+
custom_benchmark_handler = -> { yield }
|
67
|
+
|
68
|
+
described_class.configure do |config|
|
69
|
+
config.benchmark_handler = custom_benchmark_handler
|
70
|
+
end
|
71
|
+
|
72
|
+
expect(described_class.benchmark_handler).to eq(custom_benchmark_handler)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,10 +9,33 @@ $LOAD_PATH << File.join(File.dirname(__FILE__))
|
|
9
9
|
|
10
10
|
require 'action_logic'
|
11
11
|
|
12
|
+
class CustomFormatter < ActionLogic::ActionBenchmark::DefaultFormatter
|
13
|
+
def log_coordinator(benchmark_result, execution_context_name)
|
14
|
+
benchmark_log.puts("The ActionCoordinator #{execution_context_name} took #{benchmark_result} to complete.")
|
15
|
+
end
|
16
|
+
|
17
|
+
def log_use_case(benchmark_result, execution_context_name)
|
18
|
+
benchmark_log.puts("The ActionUseCase #{execution_context_name} took #{benchmark_result} to complete.")
|
19
|
+
end
|
20
|
+
|
21
|
+
def log_task(benchmark_result, execution_context_name)
|
22
|
+
benchmark_log.puts("The ActionTask #{execution_context_name} took #{benchmark_result} to complete.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class CustomHandler
|
27
|
+
def call
|
28
|
+
yield
|
29
|
+
"this is the custom handler"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
12
33
|
if ENV['BENCHMARK']
|
13
|
-
ActionLogic
|
34
|
+
ActionLogic.configure do |config|
|
14
35
|
config.benchmark = true
|
15
36
|
config.benchmark_log = File.open("benchmark.log", "w")
|
37
|
+
config.benchmark_formatter = CustomFormatter
|
38
|
+
config.benchmark_handler = CustomHandler.new
|
16
39
|
end
|
17
40
|
end
|
18
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Winfrey
|
@@ -80,8 +80,8 @@ files:
|
|
80
80
|
- action_logic.gemspec
|
81
81
|
- lib/action_logic.rb
|
82
82
|
- lib/action_logic/action_benchmark.rb
|
83
|
+
- lib/action_logic/action_benchmark/default_benchmark_block.rb
|
83
84
|
- lib/action_logic/action_benchmark/default_formatter.rb
|
84
|
-
- lib/action_logic/action_configuration.rb
|
85
85
|
- lib/action_logic/action_context.rb
|
86
86
|
- lib/action_logic/action_coordinator.rb
|
87
87
|
- lib/action_logic/action_core.rb
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/action_logic/action_validation/base_validation.rb
|
94
94
|
- lib/action_logic/action_validation/presence_validation.rb
|
95
95
|
- lib/action_logic/action_validation/type_validation.rb
|
96
|
+
- lib/action_logic/configuration.rb
|
96
97
|
- lib/action_logic/errors.rb
|
97
98
|
- lib/action_logic/version.rb
|
98
99
|
- resources/action_coordinator_diagram.png
|
@@ -101,11 +102,11 @@ files:
|
|
101
102
|
- resources/diagrams.sketch
|
102
103
|
- resources/overview_diagram.png
|
103
104
|
- spec/action_logic/action_benchmark/default_formatter_spec.rb
|
104
|
-
- spec/action_logic/action_configuration_spec.rb
|
105
105
|
- spec/action_logic/action_context_spec.rb
|
106
106
|
- spec/action_logic/action_coordinator_spec.rb
|
107
107
|
- spec/action_logic/action_task_spec.rb
|
108
108
|
- spec/action_logic/active_use_case_spec.rb
|
109
|
+
- spec/action_logic/configuration_spec.rb
|
109
110
|
- spec/fixtures/constants.rb
|
110
111
|
- spec/fixtures/coordinators.rb
|
111
112
|
- spec/fixtures/custom_types.rb
|
@@ -138,11 +139,11 @@ specification_version: 4
|
|
138
139
|
summary: Business logic abstraction
|
139
140
|
test_files:
|
140
141
|
- spec/action_logic/action_benchmark/default_formatter_spec.rb
|
141
|
-
- spec/action_logic/action_configuration_spec.rb
|
142
142
|
- spec/action_logic/action_context_spec.rb
|
143
143
|
- spec/action_logic/action_coordinator_spec.rb
|
144
144
|
- spec/action_logic/action_task_spec.rb
|
145
145
|
- spec/action_logic/active_use_case_spec.rb
|
146
|
+
- spec/action_logic/configuration_spec.rb
|
146
147
|
- spec/fixtures/constants.rb
|
147
148
|
- spec/fixtures/coordinators.rb
|
148
149
|
- spec/fixtures/custom_types.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
|
-
module ActionLogic
|
4
|
-
class ActionConfiguration
|
5
|
-
def self.configure(&block)
|
6
|
-
block.call(configuration_options)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.configuration_options
|
10
|
-
@configuration_options ||= OpenStruct.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.benchmark?
|
14
|
-
configuration_options.benchmark || false
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.benchmark_log
|
18
|
-
configuration_options.benchmark_log || $stdout
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.benchmark_formatter
|
22
|
-
custom_benchmark_formatter || default_formatter
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.reset!
|
26
|
-
@configuration_options = OpenStruct.new
|
27
|
-
@custom_benchmark_formatter = nil
|
28
|
-
@default_formatter = nil
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.custom_benchmark_formatter
|
32
|
-
@custom_benchmark_formatter ||= configuration_options.benchmark_formatter &&
|
33
|
-
configuration_options.benchmark_formatter.new
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.default_formatter
|
37
|
-
@default_formatter ||= ::ActionLogic::ActionBenchmark::DefaultFormatter.new
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'action_logic'
|
3
|
-
|
4
|
-
module ActionLogic
|
5
|
-
describe ActionConfiguration do
|
6
|
-
subject { described_class }
|
7
|
-
|
8
|
-
before do
|
9
|
-
described_class.reset!
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
described_class.reset!
|
14
|
-
end
|
15
|
-
|
16
|
-
context "benchmark" do
|
17
|
-
it "defaults the benchmark configuration option to false" do
|
18
|
-
expect(described_class.benchmark?).to be_falsey
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns true when the benchmark configuration option is set to true" do
|
22
|
-
described_class.configure do |config|
|
23
|
-
config.benchmark = true
|
24
|
-
end
|
25
|
-
|
26
|
-
expect(described_class.benchmark?).to be_truthy
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "benchmark_log" do
|
31
|
-
it "defaults benchmark log file to stdout" do
|
32
|
-
expect(described_class.benchmark_log).to eq($stdout)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns the log file when the benchmark log configuration option is set" do
|
36
|
-
temp_file = Object.new
|
37
|
-
|
38
|
-
described_class.configure do |config|
|
39
|
-
config.benchmark_log = temp_file
|
40
|
-
end
|
41
|
-
|
42
|
-
expect(described_class.benchmark_log).to eq(temp_file)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "benchmark_formatter" do
|
47
|
-
it "uses default formatter if a custom formatter is not provided" do
|
48
|
-
expect(described_class.benchmark_formatter).to be_a(ActionLogic::ActionBenchmark::DefaultFormatter)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "uses a custom formatter if one is provided" do
|
52
|
-
class CustomFormatter; end
|
53
|
-
|
54
|
-
described_class.configure do |config|
|
55
|
-
config.benchmark_formatter = CustomFormatter
|
56
|
-
end
|
57
|
-
|
58
|
-
expect(described_class.benchmark_formatter).to be_a(CustomFormatter)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|