Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: Release

on:
push:
branches: [ master ]
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [ '3.0', '3.2', 'jruby' ]
ruby-version: ['3.1', '3.2', '3.4', 'jruby-9.4.12.1']

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.0', '3.2', 'jruby']
ruby-version: ['3.1', '3.2', '3.4', 'jruby-9.4.12.1']

steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Opera Changelog

### 0.4.0 - May 22, 2025

- Stop handling exceptions
- Stop supporting ruby 3.0

### 0.3.5 - February 24, 2025

- Simplify instrumentation configuration
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in opera.gemspec
gemspec

gem 'rake', '~> 12.0'
gem 'rspec', '~> 3.0'
gem 'rake', '~> 13.2'
gem 'rspec', '~> 3.13'

group :test, :development do
gem 'dry-validation'
gem 'pry-byebug', require: false, platform: :ruby
gem 'pry-nav', require: false, platform: :jruby
gem 'pry'
gem 'pry-byebug', require: false, platforms: :ruby
end
73 changes: 38 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,70 +1,73 @@
PATH
remote: .
specs:
opera (0.3.5)
opera (0.4.0)

GEM
remote: https://rubygems.org/
specs:
bigdecimal (3.1.8)
byebug (11.1.3)
bigdecimal (3.1.9)
byebug (12.0.0)
coderay (1.1.3)
concurrent-ruby (1.3.4)
diff-lcs (1.5.1)
dry-configurable (1.2.0)
dry-core (~> 1.0, < 2)
concurrent-ruby (1.3.5)
diff-lcs (1.6.2)
dry-configurable (1.3.0)
dry-core (~> 1.1)
zeitwerk (~> 2.6)
dry-core (1.0.1)
dry-core (1.1.0)
concurrent-ruby (~> 1.0)
logger
zeitwerk (~> 2.6)
dry-inflector (1.1.0)
dry-initializer (3.1.1)
dry-logic (1.5.0)
dry-inflector (1.2.0)
dry-initializer (3.2.0)
dry-logic (1.6.0)
bigdecimal
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
dry-core (~> 1.1)
zeitwerk (~> 2.6)
dry-schema (1.13.4)
dry-schema (1.14.1)
concurrent-ruby (~> 1.0)
dry-configurable (~> 1.0, >= 1.0.1)
dry-core (~> 1.0, < 2)
dry-initializer (~> 3.0)
dry-logic (>= 1.4, < 2)
dry-types (>= 1.7, < 2)
dry-core (~> 1.1)
dry-initializer (~> 3.2)
dry-logic (~> 1.5)
dry-types (~> 1.8)
zeitwerk (~> 2.6)
dry-types (1.7.2)
dry-types (1.8.2)
bigdecimal (~> 3.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
dry-validation (1.10.0)
dry-validation (1.11.1)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
dry-initializer (~> 3.0)
dry-schema (>= 1.12, < 2)
dry-core (~> 1.1)
dry-initializer (~> 3.2)
dry-schema (~> 1.14)
zeitwerk (~> 2.6)
logger (1.7.0)
method_source (1.1.0)
pry (0.14.2)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
rake (12.3.3)
pry-byebug (3.11.0)
byebug (~> 12.0)
pry (>= 0.13, < 0.16)
rake (13.2.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.1)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
rspec-expectations (3.13.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
rspec-mocks (3.13.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rspec-support (3.13.3)
zeitwerk (2.6.18)

PLATFORMS
Expand All @@ -73,10 +76,10 @@ PLATFORMS
DEPENDENCIES
dry-validation
opera!
pry
pry-byebug
pry-nav
rake (~> 12.0)
rspec (~> 3.0)
rake (~> 13.2)
rspec (~> 3.13)

BUNDLED WITH
2.2.32
2.3.3
136 changes: 21 additions & 115 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/opera/operation/instructions/executors/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def call(instruction)
add_instruction_output(instruction, operation_result.output)
else
result.add_errors(operation_result.errors)
result.add_exceptions(operation_result.exceptions)
end

execution = result.executions.pop
Expand Down
3 changes: 0 additions & 3 deletions lib/opera/operation/instructions/executors/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def call(instruction)
instruction[:kind] = :step
operations_results = super

return if result.exceptions.any?

case operations_results
when Array
operations_results.each do |operation_result|
Expand All @@ -38,7 +36,6 @@ def call(instruction)
def add_failures(failures)
failures.each do |failure|
result.add_errors(failure.errors)
result.add_exceptions(failure.exceptions)
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/opera/operation/instructions/executors/step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def call(instruction)
operation.result.add_execution(method) unless production_mode?
operation.send(method)
end
rescue StandardError => exception
reporter&.error(exception)
operation.result.add_exception(method, "#{exception.message}, for #{operation.inspect}", classname: operation.class.name)
operation.result
end
end
end
Expand Down
19 changes: 8 additions & 11 deletions lib/opera/operation/instructions/executors/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@ def break_condition

def evaluate_instruction(instruction)
instruction[:kind] = :step
dry_result = super
validation_result = super

case dry_result
case validation_result
when Opera::Operation::Result
add_instruction_output(instruction, dry_result.output)
add_instruction_output(instruction, validation_result.output)

unless dry_result.success?
result.add_errors(dry_result.errors)
result.add_exceptions(dry_result.exceptions)
end
result.add_errors(validation_result.errors) unless validation_result.success?
when Dry::Validation::Result
add_instruction_output(instruction, dry_result.to_h)
add_instruction_output(instruction, validation_result.to_h)

result.add_errors(dry_result.errors) unless dry_result.success?
result.add_errors(validation_result.errors) unless validation_result.success?
else
exception_message = "#{dry_result.class} is not expected object. Please check: #{dry_result.inspect}"
result.add_exception(instruction[:method], exception_message, classname: operation.class.name)
raise TypeError, "#{validation_result.class} is not a valid result for 'validate' step. " \
"Please check output of '#{instruction[:method]}' step in #{operation.class.name}"
end
end
end
Expand Down
29 changes: 11 additions & 18 deletions lib/opera/operation/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,42 @@
module Opera
module Operation
class Result
class OutputError < StandardError; end
class OutputError < StandardError
attr_reader :errors

def initialize(msg, errors = {})
@errors = errors
super(msg)
end
end

attr_reader :errors, # Acumulator of errors in validation + steps
:exceptions, # Acumulator of exceptions in steps
:information, # Temporal object to store related information
:executions # Stacktrace or Pipe of the methods evaludated

attr_accessor :output # in case of success, it contains the resulting value

def initialize(output: nil, errors: {})
@errors = errors
@exceptions = {}
@information = {}
@executions = []
@output = output
end

def failure?
errors.any? || exceptions.any?
errors.any?
end

def success?
!failure?
end

def failures
errors.merge(exceptions)
errors
end

def output!
raise OutputError, 'Cannot retrieve output from a Failure.' if failure?
raise OutputError.new('Cannot retrieve output from a Failure.', errors) if failure?

output
end
Expand All @@ -60,18 +65,6 @@ def add_errors(errors)
end
end

def add_exception(method, message, classname: nil)
key = [classname, Array(method).first].compact.join('#')

@exceptions[key] = message unless @exceptions.key?(key)
end

def add_exceptions(exceptions)
exceptions.each_pair do |key, value|
add_exception(key, value)
end
end

def add_information(hash)
@information.merge!(hash)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/opera/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Opera
VERSION = '0.3.5'
VERSION = '0.4.0'
end
2 changes: 1 addition & 1 deletion opera.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.summary = 'Use simple DSL language to keep your Operations clean and maintainable'
spec.homepage = 'https://github.com/Profinda/opera'
spec.license = 'MIT'
spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
spec.required_ruby_version = Gem::Requirement.new('>= 3.1.0')

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = spec.homepage
Expand Down
Loading