lite-command 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/lite/command/attribute.rb +5 -8
- data/lib/lite/command/attribute_validator.rb +3 -4
- data/lib/lite/command/internals/call.rb +0 -1
- data/lib/lite/command/internals/context.rb +2 -2
- data/lib/lite/command/internals/execute.rb +1 -0
- data/lib/lite/command/utils.rb +6 -6
- data/lib/lite/command/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67e91e41adc24a79e5b834c8633ab65645f86e208bbd0d23dbd2e49a4462a17c
|
4
|
+
data.tar.gz: 699f3dbdef6befb271880d31d30063f10ed97517bf14ea3418574494ee2a2878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aad63061e1145000153053df04cac575065f1220bb77e09db6521e8a0f85a99c7347d049c0b941bd77c97d34c95495877dfc9066798ea278459a6df4111e4e91
|
7
|
+
data.tar.gz: 1da794d70ca0c441cc0de1b37161b02774035a4e9bff07a56f908551dc7bac751689da47e8903326c61bfc662d52d8a0036ba06ce7a0155294a9b66c294ce921
|
data/CHANGELOG.md
CHANGED
@@ -6,13 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.1.1] - 2024-10-06
|
10
|
+
### Added
|
11
|
+
- Added on_status hook to `execute!`
|
12
|
+
### Changed
|
13
|
+
- Reuse same attribute instance
|
14
|
+
|
9
15
|
## [2.1.0] - 2024-10-05
|
10
16
|
### Added
|
11
17
|
- Added passing metadata to faults
|
12
18
|
- Added `on_success` callback
|
13
19
|
- Added `on_pending`, `on_executing`, `on_complete`, and `on_interrupted` callbacks
|
14
20
|
- Added attributes and attribute validations
|
15
|
-
- Added sequences
|
21
|
+
- Added steps and sequences
|
22
|
+
- Added fault streamer
|
16
23
|
### Changed
|
17
24
|
- Check error descendency instead of type
|
18
25
|
- Rename internal modules
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Add this line to your application's Gemfile:
|
|
10
10
|
|
11
11
|
> [!NOTE]
|
12
12
|
> Gem versions `2.0.0`, `2.0.1`, `2.0.2`, and `2.0.3` are borked.
|
13
|
-
> Version
|
13
|
+
> Version `~> 2.1.0` is the suggested working version.
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
gem 'lite-command'
|
@@ -4,12 +4,10 @@ module Lite
|
|
4
4
|
module Command
|
5
5
|
class Attribute
|
6
6
|
|
7
|
-
|
7
|
+
attr_accessor :command
|
8
|
+
attr_reader :method_name, :options, :errors
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(command, method_name, options)
|
12
|
-
@command = command
|
10
|
+
def initialize(method_name, options)
|
13
11
|
@method_name = method_name
|
14
12
|
@options = options
|
15
13
|
@errors = []
|
@@ -36,7 +34,7 @@ module Lite
|
|
36
34
|
t = Array(Utils.call(command, options[:types]))
|
37
35
|
|
38
36
|
if filled?
|
39
|
-
t - [NilClass]
|
37
|
+
t.uniq - [NilClass]
|
40
38
|
else
|
41
39
|
t | [NilClass]
|
42
40
|
end
|
@@ -85,8 +83,7 @@ module Lite
|
|
85
83
|
end
|
86
84
|
|
87
85
|
def validate_attribute_filled!
|
88
|
-
return unless filled?
|
89
|
-
return unless value.nil?
|
86
|
+
return unless filled? && value.nil?
|
90
87
|
|
91
88
|
@errors << "#{method_name} must be filled"
|
92
89
|
end
|
@@ -12,15 +12,14 @@ module Lite
|
|
12
12
|
|
13
13
|
def attributes
|
14
14
|
@attributes ||=
|
15
|
-
command.class.attributes.map do |
|
16
|
-
|
15
|
+
command.class.attributes.map do |_method_name, attribute|
|
16
|
+
attribute.tap { |a| a.command = command }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def errors
|
21
21
|
@errors ||= attributes.each_with_object({}) do |attribute, h|
|
22
|
-
attribute.validate!
|
23
|
-
next if attribute.valid?
|
22
|
+
next if attribute.tap(&:validate!).valid?
|
24
23
|
|
25
24
|
h[attribute.from] ||= []
|
26
25
|
h[attribute.from] = h[attribute.from] | attribute.errors
|
@@ -86,7 +86,6 @@ module Lite
|
|
86
86
|
# eg: invalid!("idk") or failure!(fault) or error!("idk", { error_key: "some.error" })
|
87
87
|
define_method(:"#{f}!") do |object, metadata = nil|
|
88
88
|
fault(object, f, metadata)
|
89
|
-
|
90
89
|
raise Lite::Command::Fault.build(f.capitalize, self, object, dynamic: raise_dynamic_faults?)
|
91
90
|
end
|
92
91
|
end
|
@@ -13,13 +13,13 @@ module Lite
|
|
13
13
|
|
14
14
|
def attribute(*args, **options)
|
15
15
|
args.each do |method_name|
|
16
|
-
|
16
|
+
attribute = Lite::Command::Attribute.new(method_name, options)
|
17
|
+
attributes[method_name] = attribute
|
17
18
|
|
18
19
|
define_method(method_name) do
|
19
20
|
ivar = :"@#{method_name}"
|
20
21
|
return instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
21
22
|
|
22
|
-
attribute = Lite::Command::Attribute.new(self, method_name, options)
|
23
23
|
instance_variable_set(ivar, attribute.value)
|
24
24
|
end
|
25
25
|
end
|
data/lib/lite/command/utils.rb
CHANGED
@@ -16,13 +16,13 @@ module Lite
|
|
16
16
|
try(object, method_name, *args, include_private: true)
|
17
17
|
end
|
18
18
|
|
19
|
-
def call(object,
|
20
|
-
if
|
21
|
-
object.send(
|
22
|
-
elsif
|
23
|
-
object.instance_eval(&
|
19
|
+
def call(object, argument)
|
20
|
+
if argument.is_a?(Symbol) || argument.is_a?(String)
|
21
|
+
object.send(argument)
|
22
|
+
elsif argument.is_a?(Proc)
|
23
|
+
object.instance_eval(&argument)
|
24
24
|
else
|
25
|
-
|
25
|
+
argument
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/lib/lite/command/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
|
-
rubygems_version: 3.5.
|
230
|
+
rubygems_version: 3.5.21
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
233
|
summary: Ruby Command based framework (aka service objects)
|