
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
How May I Be Of service!
Hmibo is a lightweight Ruby gem that provides simple, consistent patterns for service objects. Inspired by personal patterns, it offers structured error handling and logging for business logic in your Rails applications.
Add this line to your application's Gemfile:
gem 'hmibo'
And then execute:
$ bundle install
class CreateUserService < Hmibo::Base
def initialize(name:, email:, role: 'user')
@name = name
@email = email
@role = role
super()
end
private
attr_reader :name, :email, :role
def perform
add_error("Name is required") if name.blank?
add_error("Email is required") if email.blank?
add_error("Email format is invalid") unless valid_email?
return self if errors?
user = User.create!(name: name, email: email, role: role)
@data = user
self
end
def valid_email?
email.match?(/\A[^@\s]+@[^@\s]+\z/)
end
end
# Usage
result = CreateUserService.call(name: "John Doe", email: "john@example.com")
if result.errors?
puts "Errors: #{result.errors.map { |e| e[:message] }.join(', ')}"
else
puts "User created: #{result.data.name}"
end
# Create multiple records with error handling
params = [
{ name: "John", email: "john@example.com", client_side_id: "temp-1" },
{ name: "Jane", email: "invalid-email", client_side_id: "temp-2" },
{ name: "Bob", email: "bob@example.com", client_side_id: "temp-3" }
]
result = Hmibo::BulkCreation.call(params, User)
if result.errors?
result.errors.each do |error|
puts "Error for #{error[:id]}: #{error[:message]}"
end
else
puts "All #{result.data.length} users created successfully"
end
Every service returns itself with the following interface:
result = SomeService.call(params)
result.errors? # => true/false if there are errors
result.data # => Any data set by the service
result.errors # => Array of error hashes: [{message: "...", code: 422, id: nil}]
Services provide structured error handling with automatic logging:
class ExampleService < Hmibo::Base
private
def perform
# Add individual errors
add_error("Something went wrong")
# Errors are automatically logged with context using LoggerHead
return self if errors?
@data = { success: true }
self
end
end
Hmibo integrates with LoggerHead to provide structured error logging with context:
class CreateUserService < Hmibo::Base
def perform
# Any unhandled exceptions are automatically logged with context
raise StandardError, "Database connection failed"
end
end
result = CreateUserService.call
# Automatically logs:
# ERROR -- : There was an error in CreateUserService execution: Database connection failed
# ERROR -- : /path/to/backtrace...
You can provide custom context for error logging:
class PaymentService < Hmibo::Base
private
def perform
process_payment
rescue => error
log_error(error, context: "processing payment for user #{user_id}")
add_error("Payment processing failed")
self
end
end
Hmibo provides custom exception classes:
Hmibo::ServiceError
- Base service errorHmibo has one very lightweight dependency:
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that hmibo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.