lite-command 2.0.3 → 2.1.1

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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-30 00:00:00.000000000 Z
11
+ date: 2024-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ostruct
@@ -191,13 +191,20 @@ files:
191
191
  - lib/generators/rails/command_generator.rb
192
192
  - lib/generators/rails/templates/command.rb.tt
193
193
  - lib/lite/command.rb
194
+ - lib/lite/command/attribute.rb
195
+ - lib/lite/command/attribute_validator.rb
194
196
  - lib/lite/command/base.rb
195
197
  - lib/lite/command/context.rb
196
198
  - lib/lite/command/fault.rb
197
- - lib/lite/command/internals/callable.rb
198
- - lib/lite/command/internals/executable.rb
199
- - lib/lite/command/internals/faultable.rb
200
- - lib/lite/command/internals/resultable.rb
199
+ - lib/lite/command/fault_streamer.rb
200
+ - lib/lite/command/internals/call.rb
201
+ - lib/lite/command/internals/context.rb
202
+ - lib/lite/command/internals/execute.rb
203
+ - lib/lite/command/internals/fault.rb
204
+ - lib/lite/command/internals/result.rb
205
+ - lib/lite/command/sequence.rb
206
+ - lib/lite/command/step.rb
207
+ - lib/lite/command/utils.rb
201
208
  - lib/lite/command/version.rb
202
209
  - lite-command.gemspec
203
210
  homepage: http://drexed.github.io/lite-command
@@ -220,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
227
  - !ruby/object:Gem::Version
221
228
  version: '0'
222
229
  requirements: []
223
- rubygems_version: 3.5.20
230
+ rubygems_version: 3.5.21
224
231
  signing_key:
225
232
  specification_version: 4
226
233
  summary: Ruby Command based framework (aka service objects)
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
-
6
- STATUSES = [
7
- SUCCESS = "success",
8
- NOOP = "noop",
9
- INVALID = "invalid",
10
- FAILURE = "failure",
11
- ERROR = "error"
12
- ].freeze
13
- FAULTS = (STATUSES - [SUCCESS]).freeze
14
-
15
- module Internals
16
- module Callable
17
-
18
- def self.included(base)
19
- base.extend ClassMethods
20
- end
21
-
22
- module ClassMethods
23
-
24
- def call(context = {})
25
- new(context).tap(&:execute)
26
- end
27
-
28
- def call!(context = {})
29
- new(context).tap(&:execute!)
30
- end
31
-
32
- end
33
-
34
- def call
35
- raise NotImplementedError, "call method not defined in #{self.class}"
36
- end
37
-
38
- def status
39
- @status || SUCCESS
40
- end
41
-
42
- def success?
43
- status == SUCCESS
44
- end
45
-
46
- def fault?(str = nil)
47
- !success? && reason?(str)
48
- end
49
-
50
- FAULTS.each do |f|
51
- # eg: noop? or failure?("idk")
52
- define_method(:"#{f}?") do |str = nil|
53
- status == f && reason?(str)
54
- end
55
- end
56
-
57
- private
58
-
59
- FAULTS.each do |f|
60
- # eg: error(object)
61
- define_method(:"#{f}") do |object|
62
- derive_fault_from(object)
63
- @status = f
64
- end
65
-
66
- # eg: invalid!(object)
67
- define_method(:"#{f}!") do |object|
68
- send(:"#{f}", object)
69
- raise fault(f.capitalize, object)
70
- end
71
-
72
- # eg: on_noop(exception)
73
- define_method(:"on_#{f}") do |_exception|
74
- # Define in your class to run code when a
75
- # Lite::Command::Fault or StandardError happens
76
- end
77
- end
78
-
79
- alias fail! failure!
80
-
81
- end
82
- end
83
-
84
- end
85
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
- module Internals
6
- module Faultable
7
-
8
- def self.included(base)
9
- base.class_eval do
10
- attr_reader :caused_by, :thrown_by, :reason
11
- end
12
- end
13
-
14
- def reason?(str)
15
- return true if str.nil?
16
-
17
- reason == str
18
- end
19
-
20
- def caused_fault?
21
- caused_by == self
22
- end
23
-
24
- def threw_fault?
25
- thrown_by == self
26
- end
27
-
28
- def thrown?
29
- fault? && !caused_fault?
30
- end
31
-
32
- private
33
-
34
- def throw!(command)
35
- return if command.success?
36
-
37
- send(:"#{command.status}!", command)
38
- end
39
-
40
- def derive_caused_by_from(object)
41
- (object.caused_by if object.respond_to?(:caused_by)) || self
42
- end
43
-
44
- def derive_thrown_by_from(object)
45
- if object.respond_to?(:executed?) && object.executed?
46
- object
47
- else
48
- (object.thrown_by if object.respond_to?(:thrown_by)) || caused_by
49
- end
50
- end
51
-
52
- def derive_reason_from(object)
53
- if object.respond_to?(:reason)
54
- object.reason
55
- elsif object.respond_to?(:message)
56
- "[#{object.class.name}] #{object.message}".chomp(".")
57
- else
58
- object
59
- end
60
- end
61
-
62
- def derive_fault_from(object)
63
- @caused_by ||= derive_caused_by_from(object)
64
- @thrown_by ||= derive_thrown_by_from(object)
65
- @reason ||= derive_reason_from(object)
66
- end
67
-
68
- def raise_dynamic_faults?
69
- false
70
- end
71
-
72
- # eg: Lite::Command::Noop.new(...) or Users::ResetPassword::Noop.new(...)
73
- def fault(type, thrower)
74
- klass = raise_dynamic_faults? ? self.class : Lite::Command
75
- fault = klass.const_get(type.to_s).new(reason, caused_by, self)
76
- fault.set_backtrace(thrower.backtrace) if thrower.respond_to?(:backtrace)
77
- fault
78
- end
79
-
80
- end
81
- end
82
- end
83
- end