
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
This project contains the most simple implementation of Contract written in Ruby (and maybe later in other languages).
The Contract is inspired by Design by Contracts approach and pushes Fail Fast techinque further.
So, Contract is a class with the only public method , that validates some action/behavior agains Contract Rules:
Contract validates, that:
Otherwise, Contract raises an exception with details, at least on what step behavior was broken.
Add this line to your application's Gemfile:
gem 'simple_contracts'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple_contracts
class TwitterContract < SimpleContracts::Base
def initialize(post)
super
@post = post
end
private
def guarantee_verified_delete
return true if Twitter::REST::Client.statuses(@post.tweet_id).empty?
false
end
def expect_some_action1
...
end
def expect_some_action2
...
end
# ... other rules
end
@post = Post.find(params.require(:post_id))
# Use synchronously, (raises exception, "Fails Fast"™):
TwitterContract.(@post, async: false) { TwitterAPI.destroy(@post) }
# Use asynchronously (does not affect TwitterAPI.destroy,
# but tracks any problems with TwitterContract validation)
TwitterContract.(@post) { TwitterAPI.destroy(@post) }
Bug reports and pull requests are welcome on GitHub at https://github.com/bibendi/simple_contracts.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that simple_contracts demonstrated a not healthy version release cadence and project activity because the last version was released 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.