=Methodic == Content Author:: Romain GEORGES Version:: 1.2 WWW:: http://www.ultragreen.net/projects/methodic == Description Methodic is a macro-like utility to help test, validate, control options passed by an Hash param to a method, it could help you to merge with defaults values, It raise explained exceptions and return false if the validations steps failed. == Installation In a valid Ruby environment : $ sudo zsh # gem ins methodic == Implementation * [Methodic] * [Methodic::Options] == Example === Without known options control require 'rubygems' require 'methodic' [...] # in a method def amethod ( _options = {}) myOptions = Methodic::get_options(_options) do |m| m.specify_default_value_of :country => 'France' m.specify_classes_of :name => String, :surname => String, :age => Fixnum, :country => String m.specify_presence_of :name m.specify_presence_of :surname m.specify_formats_of :name => /\w+/, :surname => /\w+/, :country => /\w+/ m.merge! end # processing method end [...] === With known options control require 'rubygems' require 'methodic' [...] # in a method def amethod ( _options = {}) myOptions = Methodic::get_options(_options,true) do |m| # all others definitions MUST be included in known options list (explained in Spec), so : m.specify_known_options [:country,:name,:surname, :age] m.specify_default_value_of :country => 'France' m.specify_classes_of :name => String, :surname => String, :age => Fixnum, :country => String m.specify_presence_of :name m.specify_presence_of :surname m.specify_formats_of :name => /\w+/, :surname => /\w+/, :country => /\w+/ m.merge! end # processing method end [...] == Copyright
Methodic (c) 2012 Romain GEORGES  for Ultragreen Software