lite-command 1.4.1 → 2.0.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.
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'lite/memoize' unless defined?(Lite::Memoize)
4
-
5
- module Lite
6
- module Command
7
- module Extensions
8
- module Memoize
9
-
10
- def cache
11
- @cache ||= Lite::Memoize::Instance.new
12
- end
13
-
14
- end
15
- end
16
- end
17
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
- module Extensions
6
- module Propagation
7
-
8
- private
9
-
10
- def assign_and_return!(instance, params)
11
- instance.assign_attributes(params)
12
- errors.merge!(instance.errors) unless instance.valid?
13
- instance
14
- end
15
-
16
- def create_and_return!(klass, params)
17
- klass = klass.create(params)
18
- merge_errors!(klass) unless klass.errors.empty?
19
- klass
20
- end
21
-
22
- def update_and_return!(instance, params)
23
- merge_errors!(instance) unless instance.update(params)
24
- instance
25
- end
26
-
27
- %i[archive destroy save].each do |action|
28
- define_method("#{action}_and_return!") do |instance|
29
- merge_errors!(instance) unless instance.send(action)
30
- instance
31
- end
32
- end
33
-
34
- end
35
- end
36
- end
37
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
- class Procedure < Complex
6
-
7
- include Lite::Command::Extensions::Errors
8
-
9
- attr_accessor :exit_on_failure
10
-
11
- def execute
12
- steps.each_with_object([]).with_index do |(command, results), i|
13
- command.call
14
-
15
- if command.respond_to?(:errors) && command.failure?
16
- failed_steps << failed_step(i, command)
17
- merge_errors!(command) if respond_to?(:errors)
18
- break results if exit_on_failure?
19
- else
20
- results << command.result
21
- end
22
- end
23
- end
24
-
25
- def exit_on_failure?
26
- @exit_on_failure ||= false
27
- end
28
-
29
- def failed_steps
30
- @failed_steps ||= []
31
- end
32
-
33
- def steps
34
- @steps ||= @args.flatten
35
- end
36
-
37
- private
38
-
39
- def failed_step(index, command)
40
- {
41
- index: index,
42
- step: index + 1,
43
- name: command.class.name,
44
- args: command.args,
45
- errors: command&.errors&.full_messages
46
- }
47
- end
48
-
49
- end
50
- end
51
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
- class Simple
6
-
7
- class << self
8
-
9
- def call(*args, **kwargs, &block)
10
- raise Lite::Command::NotImplementedError unless defined?(execute)
11
-
12
- execute(*args, **kwargs, &block)
13
- end
14
-
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
-
6
- class Success
7
-
8
- class << self
9
-
10
- def call
11
- yield
12
- end
13
-
14
- end
15
-
16
- end
17
-
18
- class Failure
19
-
20
- class << self
21
-
22
- def call
23
- # Do nothing
24
- end
25
-
26
- end
27
-
28
- end
29
-
30
- end
31
- end