light-services 2.0.0.beta1 → 2.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/lib/light/services/base.rb +27 -5
- data/lib/light/services/base_with_context.rb +4 -3
- data/lib/light/services/settings/step.rb +12 -3
- data/lib/light/services/version.rb +1 -1
- metadata +2 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3274d2f86c3525ce73f2bcdc5e90f3da5e09979ee4f5f6425a5a41ef482489a2
|
4
|
+
data.tar.gz: 2b4a0f8657f730b184b22c5eccd3273e7bdfc8abcfe7c9ec61852b38260eee48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1420e6b25d7b48cc2924a02fde1fc0f9aa9701a9c2d0faf0643ebc508e6d2eca3be6e650b42ecdd3947683899acb9ca47388bf392d0372157b73208b17f8b294
|
7
|
+
data.tar.gz: 44e1641a0ce332a8f4904ee278f3d116452335cb5186025536242a7b9714aedea55c0a3e629159b6d46feb82f4b979d1fab41baef0e4fa5fb35aa47151c778fe
|
data/.gitignore
CHANGED
data/lib/light/services/base.rb
CHANGED
@@ -26,8 +26,14 @@ module Light
|
|
26
26
|
mount_class_based_collection :outputs, item_class: Settings::Output, shortcut: :output
|
27
27
|
mount_class_based_collection :arguments, item_class: Settings::Argument, shortcut: :arg, allow_redefine: true
|
28
28
|
|
29
|
+
# Arguments
|
30
|
+
# TODO: Rename internal arguments
|
31
|
+
arg :benchmark, default: false
|
32
|
+
arg :deepness, default: 0, context: true
|
33
|
+
|
29
34
|
# Steps
|
30
35
|
step :load_defaults_and_validate
|
36
|
+
step :log_header, if: :benchmark?
|
31
37
|
|
32
38
|
# Getters
|
33
39
|
attr_reader :outputs, :arguments, :errors, :warnings
|
@@ -62,11 +68,18 @@ module Light
|
|
62
68
|
end
|
63
69
|
|
64
70
|
def call
|
65
|
-
|
66
|
-
|
71
|
+
time = Benchmark.ms do
|
72
|
+
run_steps
|
73
|
+
run_steps_with_always
|
74
|
+
|
75
|
+
copy_warnings_to_parent_service
|
76
|
+
copy_errors_to_parent_service
|
77
|
+
end
|
78
|
+
|
79
|
+
return unless benchmark
|
67
80
|
|
68
|
-
|
69
|
-
|
81
|
+
log "🟢 Finished #{self.class} in #{time}ms"
|
82
|
+
puts
|
70
83
|
end
|
71
84
|
|
72
85
|
class << self
|
@@ -83,6 +96,11 @@ module Light
|
|
83
96
|
end
|
84
97
|
end
|
85
98
|
|
99
|
+
# TODO: Add possibility to specify logger
|
100
|
+
def log(message)
|
101
|
+
puts "#{' ' * deepness}→ #{message}"
|
102
|
+
end
|
103
|
+
|
86
104
|
private
|
87
105
|
|
88
106
|
def initialize_errors
|
@@ -104,7 +122,7 @@ module Light
|
|
104
122
|
def run_steps
|
105
123
|
within_transaction do
|
106
124
|
self.class.steps.each do |name, step|
|
107
|
-
@launched_steps << name if step.run(self)
|
125
|
+
@launched_steps << name if step.run(self, benchmark: benchmark)
|
108
126
|
|
109
127
|
break if @errors.break? || @warnings.break?
|
110
128
|
end
|
@@ -146,6 +164,10 @@ module Light
|
|
146
164
|
@arguments.validate!
|
147
165
|
end
|
148
166
|
|
167
|
+
def log_header
|
168
|
+
log "🏎 Run service #{self.class}"
|
169
|
+
end
|
170
|
+
|
149
171
|
def within_transaction
|
150
172
|
if @config[:use_transactions] && defined?(ActiveRecord::Base)
|
151
173
|
ActiveRecord::Base.transaction(requires_new: true) { yield }
|
@@ -22,10 +22,11 @@ module Light
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def extend_arguments(args)
|
25
|
-
return args unless @parent_service
|
26
|
-
|
27
25
|
# TODO: Do we need `.dup` here?
|
28
|
-
@parent_service.arguments.extend_with_context(args)
|
26
|
+
args = @parent_service.arguments.extend_with_context(args) if @parent_service
|
27
|
+
args[:deepness] += 1 if args[:deepness]
|
28
|
+
|
29
|
+
args
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -22,11 +22,20 @@ module Light
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def run(instance)
|
25
|
+
def run(instance, benchmark: false)
|
26
26
|
return false unless run?(instance)
|
27
27
|
|
28
28
|
if instance.respond_to?(name, true)
|
29
|
-
|
29
|
+
if benchmark
|
30
|
+
time = Benchmark.ms do
|
31
|
+
instance.send(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
instance.log "⏱️ Step #{name} took #{time}ms"
|
35
|
+
else
|
36
|
+
instance.send(name)
|
37
|
+
end
|
38
|
+
|
30
39
|
true
|
31
40
|
else
|
32
41
|
raise Light::Services::NoStepError, "Cannot find step `#{name}` in service `#{@service_class}`"
|
@@ -48,7 +57,7 @@ module Light
|
|
48
57
|
def check_condition(condition, instance)
|
49
58
|
case condition
|
50
59
|
when Symbol
|
51
|
-
instance.
|
60
|
+
instance.send(condition)
|
52
61
|
when Proc
|
53
62
|
condition.call
|
54
63
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Emelianenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Powerful implementation of Service Object pattern for Ruby and Rails
|
14
14
|
email:
|
@@ -20,12 +20,6 @@ files:
|
|
20
20
|
- ".github/config/rubocop_linter_action.yml"
|
21
21
|
- ".github/workflows/ci.yml"
|
22
22
|
- ".gitignore"
|
23
|
-
- ".idea/.gitignore"
|
24
|
-
- ".idea/inspectionProfiles/Project_Default.xml"
|
25
|
-
- ".idea/light-services.iml"
|
26
|
-
- ".idea/misc.xml"
|
27
|
-
- ".idea/modules.xml"
|
28
|
-
- ".idea/vcs.xml"
|
29
23
|
- ".rspec"
|
30
24
|
- ".rubocop.yml"
|
31
25
|
- CHANGELOG.md
|