Release Name: 0.3.2
Notes:
= Caesars - v0.3
A simple class for rapid DSL prototyping in Ruby.
NOTE: Currently runs only with Ruby 1.9+!
== Installation
One of:
* gem install caesars
* copy lib/caesars.rb into your lib directory.
Or for GitHub fans:
* git clone git://github.com/delano/caesar.git
* gem sources -a http://gems.github.com (you only have to do this once, ever...), then:
* gem install delano-caesar
== Usage
# ------------------------------------------------------------------
# EXAMPLE 1 -- Flavour
#
class Flavour < Caesars # Subclass Caesars.
end
extend Flavour::DSL # Bring the DSL into the current namespace.
# This module is created dynamically based
# on the name of the subclass.
flavour do # Start drinking! I mean, start writing your
spicy true # domain specific language!
clamy true # Use any attribute name you want.
salty true
vodka :very_true # And any value you want.
end
p @flavour # => #<Flavour:0x3f56b0 ...>
p @flavour.spicy # => true
# ------------------------------------------------------------------
# EXAMPLE 2 -- Staff
#
# Tell Caesars which attributes have children using Caesars#bloody and
# which have blocks that you want to execute later using Caesars#virgin.
class Staff < Caesars
bloody :location
bloody :person
virgin :calculate
end
extend Staff::DSL
# The top level method is the lower case name of the class. For deeper
# names like Class::SecondLevel it will use the final name
# (i.e. secondlevel). You can supply an optional modifier name which
# will be included in the instance variable (@staff_fte).
staff :fte do
desc 'Our hard-working, "full-time" staff'
location :splashdown do
town :tsawwassen
person :steve, :sheila do
role :manager
end
person :steve do
role :cook
anger :high
hours 25
catchphrase "Rah! [strokes goatee]"
end
person :sheila do
catchphrase "This gravy tastes like food I ate in a Mexican prison."
hours rand(20)
rate "9.35/h"
calculate :salary do |gumption|
("%.2f" % [gumption * self.splashdown.sheila.rate.to_f]).to_f
end
end
person :delano do
role :cook
rate "8.35/h"
hours 57
satisfaction :low
calculate :salary do
self.splashdown.delano.rate.to_f * self.splashdown.delano.hours
end
end
end
end
p @staff_fte # => #<KitchenStaff: ...>
p @staff_fte.desc # => Our hard-working, "full-time" staff
# Deeper attributes are also available via instance methods
p @staff_fte.splashdown.delano # => {:role=>:cook, :rate=>"$8.35/h", :satisfaction=>:low}
p @staff_fte.splashdown.sheila # => {:role=>:manager, :catchphrase=>"This gravy tastes like food I ate in a Mexican prison."}
p @staff_fte.splashdown.steve # => {:role=>[:manager, :cook], :anger=>:high, :catchphrase=>"Rah! [strokes goatee]"}
p @staff_fte.splashdown.delano.satisfaction # => :low
# You can also access them using hash syntax
p @staff_fte.splashdown[:steve][:role] # => [:manager, :cook]
# The "bloody" attributes keep track of all values that are used. These are available as arrays
# via "NAME_values" methods. The goes for the virgin ones.
p @staff_fte.location_values # => [:splashdown]
p @staff_fte.person_values.uniq # => [:steve, :sheila, :delano, :angela]
p @staff_fte.calculate_values # => [:salary, :salary]
# The "virgin" methods store their blocks as Procs and are not executed automatically.
# You can call them manually and send arguments like you normally would.
p @staff_fte.splashdown.delano.salary.call # => 475.95
p @staff_fte.splashdown.sheila.salary.call(rand(100)) # => 549.77
== More Info
* GitHub[http://github.com/delano/caesar]
* Inspiration[http://www.youtube.com/watch?v=ycElb0tB9_U]
* Recipe[http://twitter.com/solutious/status/1264327499]
== Credits
* Delano Mandelbaum (delano@solutious.com)
== Thanks
* Clams, Tomatoes, Vodka, and the rest of the crew.
== License
See: LICENSE.txt
Changes:
CAESAR -- CHANGES
#### 0.3.2 (2009-03-04) ###############################
* FIX: Added file and line info for eval code (better debugging).
* CHANGE: The top level DSL method names are now determined by
by the class name. Some::ClassName becomes classname.
This is less confusing than allowing it to be anything
and makes it possible to use several DSLs in the same
namespace.
#### 0.3.1 (2009-03-04) ###############################
* NEW: Accept instances without a name
* CHANGE: Updated examples.
* NEW: More rdocs.
#### 0.3 (2009-03-04) ###############################
Initial public release
|