
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.