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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efd37a3a2fcbb8d90fef73088313f18bd281922d46594a4a57ee8dd34fcaf801
4
- data.tar.gz: 4e88ca10b986095be52c3e454e70a6c8d7b3556bb4770ed51aca80d0b9beb894
3
+ metadata.gz: 67e91e41adc24a79e5b834c8633ab65645f86e208bbd0d23dbd2e49a4462a17c
4
+ data.tar.gz: 699f3dbdef6befb271880d31d30063f10ed97517bf14ea3418574494ee2a2878
5
5
  SHA512:
6
- metadata.gz: 4123ef0a3315a8b00796a58ca65b10bc2a51905dc59e663b1ffef2ec7f9becc700ae64216cb896024564993749979cd824087a68bac1e95532311dba29cd7aa0
7
- data.tar.gz: dd4e22ead3d68f981319a372a0ce305f734f1745a31223daf725d93ff71cccbe1b4708e7b3d7ef4921f98f2e8df6c04939855b8a7e8d0e3292f5e7f3e0ec6c1a
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-command (2.1.0)
4
+ lite-command (2.1.1)
5
5
  ostruct
6
6
 
7
7
  GEM
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 `2.1.0` is the latest working 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
- # TODO: allow procs
7
+ attr_accessor :command
8
+ attr_reader :method_name, :options, :errors
8
9
 
9
- attr_reader :command, :method_name, :options, :errors
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 |method_name, options|
16
- Lite::Command::Attribute.new(command, method_name, options)
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
- attributes[method_name] = options
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
@@ -72,6 +72,7 @@ module Lite
72
72
  rescue StandardError => e
73
73
  fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
74
74
  after_execution
75
+ Utils.hook(self, :"on_#{status}", e)
75
76
  raise(e)
76
77
  else
77
78
  Utils.hook(self, :"on_#{state}")
@@ -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, method_name_or_proc)
20
- if method_name_or_proc.is_a?(Symbol) || method_name_or_proc.is_a?(String)
21
- object.send(method_name_or_proc)
22
- elsif method_name_or_proc.is_a?(Proc)
23
- object.instance_eval(&method_name_or_proc)
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
- method_name_or_proc
25
+ argument
26
26
  end
27
27
  end
28
28
 
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Command
5
5
 
6
- VERSION = "2.1.0"
6
+ VERSION = "2.1.1"
7
7
 
8
8
  end
9
9
  end
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.0
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.20
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)