Active_doc is a project mainly written in Ruby, based on the MIT license.
Dsl for executable code documentation and design by contract
= ActiveDoc
DSL for code description. It allows to create 'executable documentation' and to design by contract.
== Synopsis
class Mailer include ActiveDoc
takes :to, /^[a-z.]+@[a-z.]+.[a-z]+$/, :desc => "Receiver address" def send_mail(to)
end end
Mailer.new.send_mail("[email protected]") # => ok Mailer.new.send_mail("fake.address.org") # => raises ArgumentError
== Features
Describe code with code
Generate RDoc comments
DRY your documentation
Hash arguments description
Really up-to-date
== Requirements
== Installation
gem install active_doc
To use rake task, put something like this to your Rakefile
require 'rubygems' require 'bundler' Bundler.setup
require 'active_doc/rake/task'
in_dir = File.expand_path("../lib", FILE) out_dir = File.expand_path("../active_doc_out", FILE) ActiveDoc::Rake::Task.new(in_dir, out_dir) do
require File.expand_path("lib/phone_book.rb", File.dirname(FILE)) end
This adds task +active_doc+ to generate RDoc comments from ActiveDoc.
== Usage
To use ActiveDoc DSL in your class: include ActiveDoc
=== Method Arguments Description
Validations based on descriptions are checked every time the method is called.
When generating RDoc comments, the space between last argument description and method definition is used:
takes :name, String
def say_hallo_to(name) ... end
NOTICE: anything else in this space will be replaced.
==== Describe by Type:
takes :name, String def say_hallo_to(name) ... end
Validation: :: Raises ArgumentError, when +name+ is not of type +String+
RDoc:
==== Describe by Duck Type:
takes :name, :duck => :upcase def say_hallo_to(name) ... end
Validation: :: Raises ArgumentError, when +name+ does not respond to +:upcase+
RDoc:
==== Describe by Regexp:
takes :phone_number, /^[0-9]{9}$/ def call_to(phone_number) ... end
Validation: :: Raises ArgumentError, when regexp does not match +phone_number+
RDoc:
==== Describe by Enumeration:
takes :position, [:start, :middle, :end] def jump_to(position) ... end
Validation: :: Raises ArgumentError, when positions is not included in [:start, :middle, :end]
RDoc:
==== Describe Options Hash:
takes :options, Hash do takes :format, [:csv, :ods, :xls] end def export(options) ... end
This differs from describing method arguments, where argument description is optional. Here it's required. The reason is to prevent from (perhaps mistakenly) passing unexpected option.
==== Describe by Proc: When passing proc taking an argument, this proc is used to validate value of this method argument.
takes :number {|value| value != 0} def divide(number) ... end
Validation: :: Raises ArgumentError, unless proc.call(position)
RDoc:
=== Compatibility
This version was tested on and should be compatible with Ruby 1.9.2. It uses some features introduced in Ruby 1.9. It's not compatible with 1.8.7 and since 1.8.7 starts being legacy there isn't plan to support it unless you implement it.
=== Usage Notice Bear in mind: This gem is in early-stages of development and was not sufficiently tested in external projects.
=== Road Map
=== Contribution
Welcome
== Copyright
Copyright (c) 2011 Ivan Nečas. See LICENSE for details.