
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
conditionz
Advanced tools
Semantic Design-By-Contract pre-conditions and post-conditions.
The purpose is to raise an error when a certain condition or more are not met.
See
http://en.wikipedia.org/wiki/Design_by_contract
http://en.wikipedia.org/wiki/Precondition
http://en.wikipedia.org/wiki/Postcondition
Add to your Gemfile:
gem 'conditionz'
Then run:
bundle install
Suppose you have the following class:
class MyTime
attr_accessor :hour, :minute
def initialize(new_hour, new_minute)
hour = new_hour
minute = new_minute
end
end
Now you wish that initialize method parameters are within a certain range. Include the pre condition, and add the precondition
include Conditionz
class MyTime
attr_accessor :hour, :minute
def initialize(new_hour, new_minute)
Precondition.require 0 <= new_hour && new_hour <= 23, "Hour must be between 0 and 23"
Precondition.require 0 <= new_minute && new_minute <= 59, "Minute must be between 0 and 59"
hour = new_hour
minute = new_minute
end
end
Notice the call to Precondition.require, which receives a predicate (a boolean expression),
and an optional message string or proc.
Here's an example with proc:
Precondition.require 0 <= new_hour && new_hour <= 23, Proc.new { "Hour must be between 0 and 23 but got #{new_hour}" }
Analogously, you can ensure post conditions:
(In this example, instead of include, the fully qualified name is used
class MyQueue
attr_accessor :size
def push(item)
# some implementation of pushing to queue...
Conditionz::PostCondition.ensure size > 0
end
end
Not directly related, and preferably unit tested, but could be useful - assert a predicate
def foo
first_result = first_calculation()
Assert.that first_result > 0, "result should have been positive"
second_result = sqrt first_result
end
see MIT-LICENSE
FAQs
Unknown package
We found that conditionz 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.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.