lite-command 2.0.2 → 2.1.0

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.
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Command
5
5
 
6
- VERSION = "2.0.2"
6
+ VERSION = "2.1.0"
7
7
 
8
8
  end
9
9
  end
data/lib/lite/command.rb CHANGED
@@ -3,10 +3,17 @@
3
3
  require "generators/rails/command_generator" if defined?(Rails::Generators)
4
4
 
5
5
  require "lite/command/version"
6
- require "lite/command/internals/callable"
7
- require "lite/command/internals/executable"
8
- require "lite/command/internals/faultable"
9
- require "lite/command/internals/resultable"
10
- require "lite/command/fault"
6
+ require "lite/command/utils"
11
7
  require "lite/command/context"
8
+ require "lite/command/attribute"
9
+ require "lite/command/attribute_validator"
10
+ require "lite/command/fault"
11
+ require "lite/command/fault_streamer"
12
+ require "lite/command/internals/context"
13
+ require "lite/command/internals/call"
14
+ require "lite/command/internals/execute"
15
+ require "lite/command/internals/fault"
16
+ require "lite/command/internals/result"
12
17
  require "lite/command/base"
18
+ require "lite/command/step"
19
+ require "lite/command/sequence"
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.2
4
+ version: 2.1.0
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-29 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
@@ -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(fault_or_string)
61
- define_method(:"#{f}") do |fault_or_string|
62
- derive_fault_from(fault_or_string)
63
- @status = f
64
- end
65
-
66
- # eg: invalid!(fault_or_string)
67
- define_method(:"#{f}!") do |fault_or_string|
68
- send(:"#{f}", fault_or_string)
69
- raise_fault(Lite::Command.const_get(f.capitalize), fault_or_string)
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,88 +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(fault_or_string)
41
- (fault_or_string.caused_by if fault_or_string.respond_to?(:caused_by)) || self
42
- end
43
-
44
- def derive_thrown_by_from(fault_or_string)
45
- if fault_or_string.respond_to?(:executed?) && fault_or_string.executed?
46
- fault_or_string
47
- else
48
- (fault_or_string.thrown_by if fault_or_string.respond_to?(:thrown_by)) || caused_by
49
- end
50
- end
51
-
52
- def derive_reason_from(fault_or_string)
53
- if fault_or_string.respond_to?(:reason)
54
- fault_or_string.reason
55
- elsif fault_or_string.respond_to?(:message)
56
- "[#{fault_or_string.class.name}] #{fault_or_string.message}".chomp(".")
57
- else
58
- fault_or_string
59
- end
60
- end
61
-
62
- def derive_fault_from(fault_or_string)
63
- @caused_by ||= derive_caused_by_from(fault_or_string)
64
- @thrown_by ||= derive_thrown_by_from(fault_or_string)
65
- @reason ||= derive_reason_from(fault_or_string)
66
- end
67
-
68
- # eg: Lite::Command::Noop.new(...)
69
- def raise_fault(klass, thrower)
70
- exception = klass.new(caused_by, self, reason)
71
- exception.set_backtrace(thrower.backtrace) if thrower.respond_to?(:backtrace)
72
- raise(exception)
73
- end
74
-
75
- # eg: Users::ResetPassword::Noop.new(...)
76
- def raise_dynamic_fault(exception)
77
- fault_klass = self.class.const_get(exception.fault_klass)
78
- raise_fault(fault_klass, exception)
79
- end
80
-
81
- def raise_dynamic_faults?
82
- false
83
- end
84
-
85
- end
86
- end
87
- end
88
- end