opera 0.2.16 → 0.2.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc70b9316e79f9ca5de85afc65ea0ea0f667c8a99aa72d0828f267383b8e76c2
4
- data.tar.gz: 8ae3e726adc06851d36fdfd1314f001f678b35b7840be2bb96f833065198497a
3
+ metadata.gz: f5f102d05b4d0cbf79d677bc5697388b51f643dfa5a880426894f1c6b30b70dc
4
+ data.tar.gz: a30d504859167c71b902ac30dbc03bcf8ea048575aa08a5f0b26864e24c51be9
5
5
  SHA512:
6
- metadata.gz: f9cf2f017c1ba44975e3968912d7859514ca6c900c824130922e9d1ab7a537cdc7e0d69b0a014d8d4ceb5eb9250be7246a7671af5ff00919764e734cce333f3f
7
- data.tar.gz: 1ee6be5b16d95fd0d9174028e93784f6afa18a249553fcc2d5ef1725ac959733e4eba2598249a53c39314937299a7d55889d1919ea7e7bef670d48c712740331
6
+ metadata.gz: 69fe6abf0538339b075da566f75d8b18e60533cb33254bc25a5e495f49e89fa065a2abe2ee65c8e79cbf5b222a68284ac3f6a8a5fb37c9453a5a767d58d9caf1
7
+ data.tar.gz: 12630548b31111d555ffc9e7e95d2d07d5f6fd919feac47ffab3c152587d700a2f4460f927456242b7a23b414ae37d8a152cb9d0f3cd6ea74276894f3dad385e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Opera Changelog
2
2
 
3
+ ### 0.2.18 - September 20, 2024
4
+
5
+ - added `output!` method on Result object
6
+ - deleted `to_h` alias for `output`
7
+
8
+ ### 0.2.17 - July 8, 2024
9
+
10
+ - minor fix `mode` configuration option.
11
+
3
12
  ### 0.2.16 - June 8, 2024
4
13
 
5
14
  - add `mode` configuration option. When set to `:production` we optimize memory usage by skipping storing executions.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opera (0.2.16)
4
+ opera (0.2.18)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -880,6 +880,7 @@ Opera::Operation::Result.new(output: 'success')
880
880
  - failure? - [true, false] - Return true if any error or exception
881
881
  - output - [Anything] - Return Anything
882
882
  - output=(Anything) - Sets content of operation output
883
+ - output! - Return Anything if Success, raise exception if Failure
883
884
  - add_error(key, value) - Adds new error message
884
885
  - add_errors(Hash) - Adds multiple error messages
885
886
  - add_exception(method, message, classname: nil) - Adds new exception
@@ -62,6 +62,10 @@ module Opera
62
62
  operation.config
63
63
  end
64
64
 
65
+ def production_mode?
66
+ config.mode == Config::PRODUCTION_MODE
67
+ end
68
+
65
69
  def context
66
70
  operation.context
67
71
  end
@@ -18,7 +18,9 @@ module Opera
18
18
  end
19
19
 
20
20
  execution = result.executions.pop
21
- result.add_execution(execution => operation_result.executions)
21
+ result.add_execution(execution => operation_result.executions) unless production_mode?
22
+
23
+ operation_result
22
24
  end
23
25
 
24
26
  private
@@ -45,7 +45,7 @@ module Opera
45
45
  def add_results(instruction, results)
46
46
  add_instruction_output(instruction, results.map(&:output))
47
47
  execution = result.executions.pop
48
- result.add_execution(execution => results.map(&:executions))
48
+ result.add_execution(execution => results.map(&:executions)) unless production_mode?
49
49
  end
50
50
 
51
51
  def raise_error
@@ -8,7 +8,7 @@ module Opera
8
8
  def call(instruction)
9
9
  method = instruction[:method]
10
10
 
11
- operation.result.add_execution(method)
11
+ operation.result.add_execution(method) unless production_mode?
12
12
  operation.send(method)
13
13
  rescue StandardError => exception
14
14
  reporter&.error(exception)
@@ -17,7 +17,7 @@ module Opera
17
17
 
18
18
  case dry_result
19
19
  when Opera::Operation::Result
20
- add_instruction_output(instruction, dry_result.to_h)
20
+ add_instruction_output(instruction, dry_result.output)
21
21
 
22
22
  unless dry_result.success?
23
23
  result.add_errors(dry_result.errors)
@@ -3,14 +3,14 @@
3
3
  module Opera
4
4
  module Operation
5
5
  class Result
6
+ class OutputError < StandardError; end
7
+
6
8
  attr_reader :errors, # Acumulator of errors in validation + steps
7
9
  :exceptions, # Acumulator of exceptions in steps
8
10
  :information, # Temporal object to store related information
9
11
  :executions # Stacktrace or Pipe of the methods evaludated
10
12
 
11
- attr_accessor :output # Final object returned if success?
12
-
13
- alias to_h output
13
+ attr_accessor :output # in case of success, it contains the resulting value
14
14
 
15
15
  def initialize(output: nil, errors: {})
16
16
  @errors = errors
@@ -32,6 +32,12 @@ module Opera
32
32
  errors.merge(exceptions)
33
33
  end
34
34
 
35
+ def output!
36
+ raise OutputError, 'Cannot retrieve output from a Failure.' if failure?
37
+
38
+ output
39
+ end
40
+
35
41
  # rubocop:disable Metrics/MethodLength
36
42
  def add_error(field, message)
37
43
  @errors[field] ||= []
@@ -71,16 +77,8 @@ module Opera
71
77
  end
72
78
 
73
79
  def add_execution(step)
74
- return if config.production_mode?
75
-
76
80
  @executions << step
77
81
  end
78
-
79
- private
80
-
81
- def config
82
- Config
83
- end
84
82
  end
85
83
  end
86
84
  end
data/lib/opera/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Opera
4
- VERSION = '0.2.16'
4
+ VERSION = '0.2.18'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - ProFinda Development Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation