action_logic 0.2.1 → 0.2.2
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 +5 -5
- data/lib/action_logic.rb +2 -0
- data/lib/action_logic/action_benchmark.rb +19 -0
- data/lib/action_logic/action_configuration.rb +25 -0
- data/lib/action_logic/action_coordinator.rb +2 -0
- data/lib/action_logic/action_core.rb +6 -0
- data/lib/action_logic/action_task.rb +2 -0
- data/lib/action_logic/action_use_case.rb +2 -0
- data/lib/action_logic/version.rb +1 -1
- data/spec/action_logic/action_configuration_spec.rb +42 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb908cdf21b4822673902f5b19eed95206101d34
|
4
|
+
data.tar.gz: 88acebe974c5bdfc84a0f063b3de6167aaf8d089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b207eff368d0401c5b3110bd62de42929198aae35993fd80f72746e8628e6d8dffd0283aa04bd26d103445ac0c091c843915ac83e8f3e0c2285dc1fd99c40f
|
7
|
+
data.tar.gz: 061f6bc8f7ae853638320cf79d0c6a2e154d110c322482887e9e74719978d5e4dd71e1c9f8b17342a4901bbef6d055cf047cd7cb2ccacab56410128b6f7ba894
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -589,7 +589,7 @@ class ActionTaskExample
|
|
589
589
|
end
|
590
590
|
end
|
591
591
|
|
592
|
-
ActionTaskExample.execute # ~> [:required_attribute1] (ActionLogic::MissingAttributeError)
|
592
|
+
ActionTaskExample.execute # ~> context: ActionTaskExample message: [:required_attribute1] (ActionLogic::MissingAttributeError)
|
593
593
|
```
|
594
594
|
|
595
595
|
Attribute validations are defined in the same way regardless of the timing of the validation ([before](#before-validations), [after](#after-validations) or
|
@@ -657,7 +657,7 @@ class ActionTaskExample
|
|
657
657
|
end
|
658
658
|
end
|
659
659
|
|
660
|
-
ActionTaskExample.execute # ~>
|
660
|
+
ActionTaskExample.execute # ~> context: ActionTaskExample message: Attribute: integer_test with value: 1.0 was expected to be of type Fixnum but is Float (ActionLogic::AttributeTypeError)
|
661
661
|
```
|
662
662
|
|
663
663
|
In addition to the above default types it is possible to also validate against user defined types.
|
@@ -709,7 +709,7 @@ class ActionTaskExample
|
|
709
709
|
end
|
710
710
|
end
|
711
711
|
|
712
|
-
ActionTaskExample.execute # ~>
|
712
|
+
ActionTaskExample.execute # ~> context: ActionTaskExample message: Attribute: example_attribute with value: #<OtherClass:0x007fb5ca04edb8> was expected to be of type ExampleClass but is OtherClass (ActionLogic::AttributeTypeError)
|
713
713
|
```
|
714
714
|
|
715
715
|
Attribute and type validations are very helpful, but in some situations this is not enough. Additionally, `ActionLogic` provides presence validation so you can also verify that
|
@@ -751,7 +751,7 @@ class ActionTaskExample
|
|
751
751
|
end
|
752
752
|
end
|
753
753
|
|
754
|
-
ActionTaskExample.execute(:example_attribute => nil) # ~>
|
754
|
+
ActionTaskExample.execute(:example_attribute => nil) # ~> context: ActionTaskExample message: Attribute: example_attribute is missing value in context but presence validation was specified (ActionLogic::PresenceError)
|
755
755
|
```
|
756
756
|
|
757
757
|
### Custom Presence Validations
|
@@ -792,7 +792,7 @@ class ActionTaskExample
|
|
792
792
|
end
|
793
793
|
end
|
794
794
|
|
795
|
-
ActionTaskExample.execute(:example_attribute => []) # ~>
|
795
|
+
ActionTaskExample.execute(:example_attribute => []) # ~> context: ActionTaskExample message: Attribute: example_attribute is missing value in context but custom presence validation was specified (ActionLogic::PresenceError)
|
796
796
|
```
|
797
797
|
|
798
798
|
In the above example, we have failed to pass the presence validation for `example_attribute` because the value of `example_attribute` is an empty array. When
|
data/lib/action_logic.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'action_logic/version'
|
2
|
+
require 'action_logic/action_configuration'
|
2
3
|
require 'action_logic/action_context'
|
3
4
|
require 'action_logic/action_coordinator'
|
4
5
|
require 'action_logic/action_core'
|
@@ -6,3 +7,4 @@ require 'action_logic/action_task'
|
|
6
7
|
require 'action_logic/action_use_case'
|
7
8
|
require 'action_logic/action_validation'
|
8
9
|
require 'action_logic/errors'
|
10
|
+
require 'benchmark'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActionLogic
|
2
|
+
module ActionBenchmark
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def with_benchmark(class_context, &block)
|
6
|
+
if ActionConfiguration.benchmark?
|
7
|
+
context = nil
|
8
|
+
benchmark_result = Benchmark.measure { context = block.call }
|
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)
|
11
|
+
context
|
12
|
+
else
|
13
|
+
block.call
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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.reset!
|
22
|
+
@configuration_options = OpenStruct.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'action_logic/action_core'
|
2
2
|
require 'action_logic/action_validation'
|
3
|
+
require 'action_logic/action_benchmark'
|
3
4
|
|
4
5
|
module ActionLogic
|
5
6
|
module ActionCoordinator
|
@@ -10,6 +11,7 @@ module ActionLogic
|
|
10
11
|
klass.extend ClassMethods
|
11
12
|
klass.extend ActionLogic::ActionCore::ClassMethods
|
12
13
|
klass.extend ActionLogic::ActionValidation::ClassMethods
|
14
|
+
klass.extend ActionLogic::ActionBenchmark::ClassMethods
|
13
15
|
end
|
14
16
|
|
15
17
|
module ClassMethods
|
@@ -17,6 +17,12 @@ module ActionLogic
|
|
17
17
|
|
18
18
|
module ClassMethods
|
19
19
|
def around(params, &block)
|
20
|
+
with_benchmark(self) do
|
21
|
+
execute!(params, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute!(params, &block)
|
20
26
|
execution_context = self.new(params)
|
21
27
|
|
22
28
|
return execution_context.context if execution_context.break?
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'action_logic/action_core'
|
2
2
|
require 'action_logic/action_validation'
|
3
|
+
require 'action_logic/action_benchmark'
|
3
4
|
|
4
5
|
module ActionLogic
|
5
6
|
module ActionTask
|
@@ -10,6 +11,7 @@ module ActionLogic
|
|
10
11
|
klass.extend ClassMethods
|
11
12
|
klass.extend ActionLogic::ActionCore::ClassMethods
|
12
13
|
klass.extend ActionLogic::ActionValidation::ClassMethods
|
14
|
+
klass.extend ActionLogic::ActionBenchmark::ClassMethods
|
13
15
|
end
|
14
16
|
|
15
17
|
module ClassMethods
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'action_logic/action_core'
|
2
2
|
require 'action_logic/action_validation'
|
3
|
+
require 'action_logic/action_benchmark'
|
3
4
|
|
4
5
|
module ActionLogic
|
5
6
|
module ActionUseCase
|
@@ -10,6 +11,7 @@ module ActionLogic
|
|
10
11
|
klass.extend ClassMethods
|
11
12
|
klass.extend ActionLogic::ActionCore::ClassMethods
|
12
13
|
klass.extend ActionLogic::ActionValidation::ClassMethods
|
14
|
+
klass.extend ActionLogic::ActionBenchmark::ClassMethods
|
13
15
|
end
|
14
16
|
|
15
17
|
module ClassMethods
|
data/lib/action_logic/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
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
|
+
context "benchmark" do
|
13
|
+
it "defaults the benchmark configuration option to false" do
|
14
|
+
expect(described_class.benchmark?).to be_falsey
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true when the benchmark configuration option is set to true" do
|
18
|
+
described_class.configure do |config|
|
19
|
+
config.benchmark = true
|
20
|
+
end
|
21
|
+
|
22
|
+
expect(described_class.benchmark?).to be_truthy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "benchmark_log" do
|
27
|
+
it "defaults benchmark log file to stdout" do
|
28
|
+
expect(described_class.benchmark_log).to eq($stdout)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns the log file when the benchmark log configuration option is set" do
|
32
|
+
temp_file = Object.new
|
33
|
+
|
34
|
+
described_class.configure do |config|
|
35
|
+
config.benchmark_log = temp_file
|
36
|
+
end
|
37
|
+
|
38
|
+
expect(described_class.benchmark_log).to eq(temp_file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Winfrey
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- action_logic.gemspec
|
81
81
|
- lib/action_logic.rb
|
82
|
+
- lib/action_logic/action_benchmark.rb
|
83
|
+
- lib/action_logic/action_configuration.rb
|
82
84
|
- lib/action_logic/action_context.rb
|
83
85
|
- lib/action_logic/action_coordinator.rb
|
84
86
|
- lib/action_logic/action_core.rb
|
@@ -92,6 +94,7 @@ files:
|
|
92
94
|
- resources/action_use_case_diagram.png
|
93
95
|
- resources/diagrams.sketch
|
94
96
|
- resources/overview_diagram.png
|
97
|
+
- spec/action_logic/action_configuration_spec.rb
|
95
98
|
- spec/action_logic/action_context_spec.rb
|
96
99
|
- spec/action_logic/action_coordinator_spec.rb
|
97
100
|
- spec/action_logic/action_task_spec.rb
|
@@ -127,6 +130,7 @@ signing_key:
|
|
127
130
|
specification_version: 4
|
128
131
|
summary: Business logic abstraction
|
129
132
|
test_files:
|
133
|
+
- spec/action_logic/action_configuration_spec.rb
|
130
134
|
- spec/action_logic/action_context_spec.rb
|
131
135
|
- spec/action_logic/action_coordinator_spec.rb
|
132
136
|
- spec/action_logic/action_task_spec.rb
|