lite-command 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +23 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +127 -100
- data/README.md +85 -231
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/generators/rails/command_generator.rb +5 -5
- data/lib/generators/rails/templates/command.rb.tt +1 -1
- data/lib/lite/command/base.rb +49 -0
- data/lib/lite/command/context.rb +32 -0
- data/lib/lite/command/fault.rb +54 -0
- data/lib/lite/command/internals/callable.rb +158 -0
- data/lib/lite/command/internals/executable.rb +83 -0
- data/lib/lite/command/internals/resultable.rb +78 -0
- data/lib/lite/command/version.rb +1 -1
- data/lib/lite/command.rb +9 -13
- data/lite-command.gemspec +28 -29
- metadata +13 -42
- data/lib/lite/command/complex.rb +0 -52
- data/lib/lite/command/exceptions.rb +0 -10
- data/lib/lite/command/extensions/errors.rb +0 -88
- data/lib/lite/command/extensions/memoize.rb +0 -17
- data/lib/lite/command/extensions/propagation.rb +0 -37
- data/lib/lite/command/procedure.rb +0 -51
- data/lib/lite/command/simple.rb +0 -19
- data/lib/lite/command/states.rb +0 -31
@@ -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
|
data/lib/lite/command/simple.rb
DELETED
@@ -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
|
data/lib/lite/command/states.rb
DELETED
@@ -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
|