Hi.
I have released a new library -- "NeuronCheck"
It is the library for checking parameters, return value, preconditions and
postconditions with declarative syntax.
== Documents
http://ruby.morphball.net/neuroncheck/en/doc/
== Introduction
NeuronCheck is a library for following 2 functions with declarative syntax.
1. Checking method parameters and return value
2. Checking pre-conditions and post-conditions
It has 2 features. First one is that it can be carried out various types of
checks with a simple description. The other one is that it can be introduced
with little adverse effect on the production environment performance.
In addition, in the form incorporated into other library, you can also use
only the check function part.
NeuronCheck has been made is inspired by Rubype gem and by Contract
Programming of the concept of Eiffel and D language. We aim to
"in the form of an executable document, describes the type information and
pre-conditions, so as to perform the check in accordance with its description"
thing.
== Example code
require 'neuroncheck'
class Converter
# Activate NeuronCheck on Converter class
extend NeuronCheck
# NeuronCheck check declaration block
ndecl {
# Arguments declaration (this method receives 3 arguments - 1st is
# String, 2nd is any object has #each method, and 3rd is Numeric or nil)
args String, respondable(:each), [Numeric, nil]
# Return value declaration (this method returns self)
returns :self
# Precondition check
precond do
assert{ threshold >= 0 }
end
}
# Actual method definition
def convert(text, keywords, threshold = nil)
# (main process)
end
end
conv = Converter.new
conv.convert(100, ['Blog', 'Learning'], 0.5)
# => main.rb:28:in `<main>': 1st argument `text' of
`Converter#convert' must be String, but was 100 (NeuronCheckError)
# got: 100
# signature: Converter#convert(text:String,
keywords:respondable(:each), threshold:[Numeric, nil]) -> self
# declared at: main.rb:10:in `block in <class:Converter>'
== Requirement
Ruby 2.0.0 or later
But, Some shorthand syntaxes is usable only in Ruby 2.1.0 or later. (because
it uses Refinement function)
== Install
% gem install neuroncheck
== Others
- NeuronCheck has just born. I want your comment, request, proposal or
bug report. Please send E-mail or message from website or github issues
page
Website: <http://ruby.morphball.net/neuroncheck/en/>
Github project page: <https://github.com/tetradice/neuroncheck>
Happy hacking!
···
--
Dice (rubyist in japan)
Mail: tetradice@gmail.com
Twitter: @tetradice_ruby