S
Sean O'Halpin
Doodle is a Ruby library and gem for simplifying the definition of
Ruby classes by making attributes and their properties more
declarative.
Doodle is eco-friendly =96 it does not globally modify Object, Class or
Module, nor does it pollute instances with its own instance variables
(i.e. it plays nice with yaml). Future versions will try to be even
more unobtrusive.
It is similar to but different from libraries such as Ara Howard's
attributes and traits and likewise owes something to the famous
metakoans Ruby quiz.
Features:
* initialization
o using positional arguments
o with named arguments
o by block
* defaults
* initial values
* validation at attribute and class levels
* conversions for attributes and classes
* collectors to help in defining simple DSLs
* works for classes, instances and singletons
Putting all this together, you can initialize objects like this:
event =3D Event "Festival" do
date '2008-04-01'
place "The muddy field"
place "Beer tent" do
event "Drinking"
end
end
pp event
#<Event:0x595394
@date=3D#<Date: 4909115/2,0,2299161>,
@locations=3D
[#<Location:0x5913d4 @events=3D[], @name=3D"The muddy field">,
#<Location:0x58ef58
@events=3D[#<Event:0x58d630 @locations=3D[], @name=3D"Drinking">],
@name=3D"Beer tent">],
@name=3D"Festival">
from a class definition like this:
require 'date'
require 'pp'
require 'doodle'
class Location < Doodle::Base
has :name, :kind =3D> String
has :events, :init =3D> [], :collect =3D> :Event
end
class Event < Doodle::Base
has :name, :kind =3D> String
has :date do
kind Date
default { Date.today }
must 'be >=3D today' do |value|
value >=3D Date.today
end
from String do |s|
Date.parse(s)
end
end
has :locations, :init =3D> [], :collect =3D> {lace =3D> "Location"}
end
To install:
$ sudo gem install doodle
or
C:\> gem install doodle
For more info, see http://doodle.rubyforge.org/
Ruby classes by making attributes and their properties more
declarative.
Doodle is eco-friendly =96 it does not globally modify Object, Class or
Module, nor does it pollute instances with its own instance variables
(i.e. it plays nice with yaml). Future versions will try to be even
more unobtrusive.
It is similar to but different from libraries such as Ara Howard's
attributes and traits and likewise owes something to the famous
metakoans Ruby quiz.
Features:
* initialization
o using positional arguments
o with named arguments
o by block
* defaults
* initial values
* validation at attribute and class levels
* conversions for attributes and classes
* collectors to help in defining simple DSLs
* works for classes, instances and singletons
Putting all this together, you can initialize objects like this:
event =3D Event "Festival" do
date '2008-04-01'
place "The muddy field"
place "Beer tent" do
event "Drinking"
end
end
pp event
#<Event:0x595394
@date=3D#<Date: 4909115/2,0,2299161>,
@locations=3D
[#<Location:0x5913d4 @events=3D[], @name=3D"The muddy field">,
#<Location:0x58ef58
@events=3D[#<Event:0x58d630 @locations=3D[], @name=3D"Drinking">],
@name=3D"Beer tent">],
@name=3D"Festival">
from a class definition like this:
require 'date'
require 'pp'
require 'doodle'
class Location < Doodle::Base
has :name, :kind =3D> String
has :events, :init =3D> [], :collect =3D> :Event
end
class Event < Doodle::Base
has :name, :kind =3D> String
has :date do
kind Date
default { Date.today }
must 'be >=3D today' do |value|
value >=3D Date.today
end
from String do |s|
Date.parse(s)
end
end
has :locations, :init =3D> [], :collect =3D> {lace =3D> "Location"}
end
To install:
$ sudo gem install doodle
or
C:\> gem install doodle
For more info, see http://doodle.rubyforge.org/