action_logic 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/action_logic.rb +4 -2
- data/lib/action_logic/action_benchmark.rb +26 -7
- data/lib/action_logic/action_benchmark/default_formatter.rb +30 -0
- data/lib/action_logic/action_configuration.rb +15 -0
- data/lib/action_logic/action_coordinator.rb +4 -0
- data/lib/action_logic/action_task.rb +4 -0
- data/lib/action_logic/action_use_case.rb +4 -0
- data/lib/action_logic/version.rb +1 -1
- data/spec/action_logic/action_benchmark/default_formatter_spec.rb +29 -0
- data/spec/action_logic/action_configuration_spec.rb +20 -0
- data/spec/action_logic/action_coordinator_spec.rb +4 -0
- data/spec/action_logic/action_task_spec.rb +3 -0
- data/spec/action_logic/active_use_case_spec.rb +3 -0
- data/spec/fixtures/coordinators.rb +2 -0
- data/spec/fixtures/tasks.rb +2 -1
- data/spec/fixtures/use_cases.rb +2 -0
- data/spec/spec_helper.rb +8 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4115622aa03370f1c78ca57d8c45670d2c52bf
|
4
|
+
data.tar.gz: f1687c7f429d52c51369d91814cde3927a3eadd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e4f68bd7c54c1a838fdd81f399c9031c25a1409c423ad622d68203cbde71532f27b6df86a2c50437d6c0d23d360938df536b6593c550ce4580ea3302ac1054
|
7
|
+
data.tar.gz: 453fa766e4778a577fcea58ffdfc2c59b8fb256ca42322136874926f1f5bf56748aa9fc79998edbbaff6eec696c7e942e91d6b3e6034d7c13c3ca72580b5d171
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/action_logic.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'action_logic/version'
|
2
1
|
require 'action_logic/action_configuration'
|
3
2
|
require 'action_logic/action_context'
|
4
3
|
require 'action_logic/action_coordinator'
|
@@ -6,5 +5,8 @@ require 'action_logic/action_core'
|
|
6
5
|
require 'action_logic/action_task'
|
7
6
|
require 'action_logic/action_use_case'
|
8
7
|
require 'action_logic/action_validation'
|
8
|
+
require 'action_logic/action_benchmark'
|
9
|
+
require 'action_logic/action_benchmark/default_formatter'
|
10
|
+
|
9
11
|
require 'action_logic/errors'
|
10
|
-
require '
|
12
|
+
require 'action_logic/version'
|
@@ -1,19 +1,38 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
1
3
|
module ActionLogic
|
2
4
|
module ActionBenchmark
|
3
5
|
|
4
6
|
module ClassMethods
|
5
|
-
def with_benchmark(
|
6
|
-
if
|
7
|
-
context =
|
8
|
-
benchmark_result
|
9
|
-
ActionConfiguration.benchmark_log.printf("%60s: %15s %15s %15s %15s\n", "Context", "User Time", "System Time", "Total Time", "Real Time")
|
10
|
-
ActionConfiguration.benchmark_log.printf("%60s: %15f %15f %15f %15f\n\n", class_context, benchmark_result.utime, benchmark_result.stime, benchmark_result.total, benchmark_result.real)
|
7
|
+
def with_benchmark(execution_context, &block)
|
8
|
+
if benchmark?
|
9
|
+
benchmark_result, context = benchmark!(&block)
|
10
|
+
log!(benchmark_result, execution_context)
|
11
11
|
context
|
12
12
|
else
|
13
13
|
block.call
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
17
|
+
private
|
18
|
+
|
19
|
+
def benchmark?
|
20
|
+
ActionConfiguration.benchmark?
|
21
|
+
end
|
22
|
+
|
23
|
+
def benchmark!(&block)
|
24
|
+
context = nil
|
25
|
+
benchmark_result = Benchmark.measure { context = block.call }
|
26
|
+
[benchmark_result, context]
|
27
|
+
end
|
28
|
+
|
29
|
+
def log!(benchmark_result, execution_context)
|
30
|
+
benchmark_formatter.send(execution_context.__private__type, benchmark_result, execution_context.name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def benchmark_formatter
|
34
|
+
ActionConfiguration.benchmark_formatter
|
35
|
+
end
|
36
|
+
end
|
18
37
|
end
|
19
38
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActionLogic
|
2
|
+
module ActionBenchmark
|
3
|
+
class DefaultFormatter
|
4
|
+
def initialize(benchmark_log: ActionConfiguration.benchmark_log)
|
5
|
+
@benchmark_log = benchmark_log
|
6
|
+
end
|
7
|
+
|
8
|
+
def format(benchmark_result, context_name)
|
9
|
+
benchmark_log.printf("%-10s %-50s %-10s %-10f %-10s %-10f %-10s %-10f %-10s %-10f\n",
|
10
|
+
"context:",
|
11
|
+
context_name,
|
12
|
+
"user_time:",
|
13
|
+
benchmark_result.utime,
|
14
|
+
"system_time:",
|
15
|
+
benchmark_result.stime,
|
16
|
+
"total_time:",
|
17
|
+
benchmark_result.total,
|
18
|
+
"real_time:",
|
19
|
+
benchmark_result.real)
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :coordinator, :format
|
23
|
+
alias_method :use_case, :format
|
24
|
+
alias_method :task, :format
|
25
|
+
|
26
|
+
private
|
27
|
+
attr_reader :benchmark_log
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -18,8 +18,23 @@ module ActionLogic
|
|
18
18
|
configuration_options.benchmark_log || $stdout
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.benchmark_formatter
|
22
|
+
custom_benchmark_formatter || default_formatter
|
23
|
+
end
|
24
|
+
|
21
25
|
def self.reset!
|
22
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
|
23
38
|
end
|
24
39
|
end
|
25
40
|
end
|
data/lib/action_logic/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ActionLogic::ActionBenchmark
|
4
|
+
describe DefaultFormatter do
|
5
|
+
|
6
|
+
let(:benchmark_log) { StringIO.new }
|
7
|
+
let(:benchmark_result) { double(:benchmark_result, utime: 0.00003, stime: 0.00002, total: 0.00001, real: 0.00030) }
|
8
|
+
|
9
|
+
subject { described_class.new(benchmark_log: benchmark_log) }
|
10
|
+
|
11
|
+
it "writes the benchmark result to the log for an ActionCoordinator" do
|
12
|
+
subject.coordinator(benchmark_result, "CoordinatorContext")
|
13
|
+
expect(benchmark_log.string).to\
|
14
|
+
eq "context: CoordinatorContext user_time: 0.000030 system_time: 0.000020 total_time: 0.000010 real_time: 0.000300 \n"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "writes the benchmark result to the log for an ActionUseCase" do
|
18
|
+
subject.coordinator(benchmark_result, "UseCaseContext")
|
19
|
+
expect(benchmark_log.string).to\
|
20
|
+
eq "context: UseCaseContext user_time: 0.000030 system_time: 0.000020 total_time: 0.000010 real_time: 0.000300 \n"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "writes the benchmark result to the log for an ActionTask" do
|
24
|
+
subject.coordinator(benchmark_result, "TaskContext")
|
25
|
+
expect(benchmark_log.string).to\
|
26
|
+
eq "context: TaskContext user_time: 0.000030 system_time: 0.000020 total_time: 0.000010 real_time: 0.000300 \n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -5,6 +5,10 @@ module ActionLogic
|
|
5
5
|
describe ActionConfiguration do
|
6
6
|
subject { described_class }
|
7
7
|
|
8
|
+
before do
|
9
|
+
described_class.reset!
|
10
|
+
end
|
11
|
+
|
8
12
|
after do
|
9
13
|
described_class.reset!
|
10
14
|
end
|
@@ -38,5 +42,21 @@ module ActionLogic
|
|
38
42
|
expect(described_class.benchmark_log).to eq(temp_file)
|
39
43
|
end
|
40
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
|
41
61
|
end
|
42
62
|
end
|
@@ -5,6 +5,10 @@ require 'fixtures/custom_types'
|
|
5
5
|
|
6
6
|
module ActionLogic
|
7
7
|
describe ActionCoordinator do
|
8
|
+
it "knows its type" do
|
9
|
+
expect(TestCoordinator1.__private__type).to eq(:coordinator)
|
10
|
+
end
|
11
|
+
|
8
12
|
context "no failures and no halts" do
|
9
13
|
it "evaluates all use cases defined by the state transition plan" do
|
10
14
|
result = TestCoordinator1.execute()
|
@@ -5,6 +5,9 @@ require 'fixtures/custom_types'
|
|
5
5
|
|
6
6
|
module ActionLogic
|
7
7
|
describe ActionUseCase do
|
8
|
+
it "knows its type" do
|
9
|
+
expect(SimpleTestUseCase.__private__type).to eq(:use_case)
|
10
|
+
end
|
8
11
|
|
9
12
|
it "returns an instance of ActionContext" do
|
10
13
|
result = SimpleTestUseCase.execute()
|
data/spec/fixtures/tasks.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'action_logic'
|
2
2
|
require 'fixtures/custom_types'
|
3
3
|
require 'fixtures/constants'
|
4
|
-
|
4
|
+
# :nocov:
|
5
5
|
class SimpleTestTask
|
6
6
|
include ActionLogic::ActionTask
|
7
7
|
|
@@ -284,3 +284,4 @@ class HaltTestTask
|
|
284
284
|
context.halt!(Constants::HALT_MESSAGE)
|
285
285
|
end
|
286
286
|
end
|
287
|
+
# :nocov:
|
data/spec/fixtures/use_cases.rb
CHANGED
@@ -2,6 +2,7 @@ require 'action_logic'
|
|
2
2
|
require 'fixtures/tasks'
|
3
3
|
require 'fixtures/constants'
|
4
4
|
|
5
|
+
# :nocov:
|
5
6
|
class SimpleTestUseCase
|
6
7
|
include ActionLogic::ActionUseCase
|
7
8
|
|
@@ -416,3 +417,4 @@ class UseCaseHaltTestTask
|
|
416
417
|
context.halt!(Constants::HALT_MESSAGE)
|
417
418
|
end
|
418
419
|
end
|
420
|
+
# :nocov:
|
data/spec/spec_helper.rb
CHANGED
@@ -9,8 +9,15 @@ $LOAD_PATH << File.join(File.dirname(__FILE__))
|
|
9
9
|
|
10
10
|
require 'action_logic'
|
11
11
|
|
12
|
+
if ENV['BENCHMARK']
|
13
|
+
ActionLogic::ActionConfiguration.configure do |config|
|
14
|
+
config.benchmark = true
|
15
|
+
config.benchmark_log = File.open("benchmark.log", "w")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
12
19
|
RSpec.configure do |c|
|
13
|
-
|
20
|
+
c.fail_fast = true
|
14
21
|
c.color = true
|
15
22
|
c.formatter = 'documentation'
|
16
23
|
c.order = 'rand'
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Winfrey
|
@@ -80,6 +80,7 @@ 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_formatter.rb
|
83
84
|
- lib/action_logic/action_configuration.rb
|
84
85
|
- lib/action_logic/action_context.rb
|
85
86
|
- lib/action_logic/action_coordinator.rb
|
@@ -99,6 +100,7 @@ files:
|
|
99
100
|
- resources/action_use_case_diagram.png
|
100
101
|
- resources/diagrams.sketch
|
101
102
|
- resources/overview_diagram.png
|
103
|
+
- spec/action_logic/action_benchmark/default_formatter_spec.rb
|
102
104
|
- spec/action_logic/action_configuration_spec.rb
|
103
105
|
- spec/action_logic/action_context_spec.rb
|
104
106
|
- spec/action_logic/action_coordinator_spec.rb
|
@@ -135,6 +137,7 @@ signing_key:
|
|
135
137
|
specification_version: 4
|
136
138
|
summary: Business logic abstraction
|
137
139
|
test_files:
|
140
|
+
- spec/action_logic/action_benchmark/default_formatter_spec.rb
|
138
141
|
- spec/action_logic/action_configuration_spec.rb
|
139
142
|
- spec/action_logic/action_context_spec.rb
|
140
143
|
- spec/action_logic/action_coordinator_spec.rb
|