Class | Caesars |
In: |
lib/caesars.rb
lib/caesars/config.rb lib/caesars/exceptions.rb lib/caesars/hash.rb |
Parent: | Object |
A helper for loading a DSL from a config file.
Usage:
class Staff < Caesars; end; class StaffConfig < Caesars::Config dsl Staff::DSL end @config = StaffConfig.new('/path/2/staff_dsl.rb') p @config.staff # => <Staff:0x7ea450 ... >
VERSION | = | "0.7.4" |
HASH_TYPE | = | (RUBY_VERSION =~ /1.9/) ? ::Hash : Caesars::OrderedHash |
DIGEST_TYPE | = | Digest::SHA1 |
caesars_properties | [RW] | An instance of Caesars::Hash which contains the data specified by your DSL |
Specify a method that should delay execution of its block. Here‘s an example:
class Food < Caesars chill :count end food do taste :delicious count do |items| puts items + 2 end end @food.count.call(3) # => 5
Specify a method that should store it‘s args as nested Arrays Here‘s an example:
class Food < Caesars forced_array :sauce end food do taste :delicious sauce :tabasco, :worcester sauce :franks end @food.sauce # => [[:tabasco, :worcester], [:franks]]
The blocks for elements that are specified as forced_array will be chilled (stored as Proc objects). The block is put at the end of the Array. e.g.
food do sauce :arg1, :arg2 do ... end end @food.sauce # => [[:inline_method, :arg1, :arg2, #<Proc:0x1fa552>]]
Force the specified keyword to always be treated as a hash. Example:
startup do disks do create "/path/2" # Available as hash: [action][disks][create][/path/2] == {} create "/path/4" do # Available as hash: [action][disks][create][/path/4] == {size => 14} size 14 end end end
Specify a method that should always be ignored. Here‘s an example:
class Food < Caesars forced_ignore :taste end food do taste :delicious end @food.taste # => nil
Executes automatically when Caesars is subclassed. This creates the YourClass::DSL module which contains a single method named after YourClass that is used to catch the top level DSL method.
For example, if your class is called Glasses::HighBall, your top level method would be: highball.
highball :mine do volume "9oz" end
Add keyword to the list of known symbols for this instances as well as to the master known symbols list. See: known_symbol?
Looks for the specific attribute specified. criteria is an array of attribute names, orders according to their relationship. The last element is considered to the desired attribute. It can be an array.
Unlike find_deferred, it will return only the value specified, otherwise nil.
Look for an attribute, bubbling up through the parents until it‘s found. criteria is an array of hierarchical attributes, ordered according to their relationship. The last element is the desired attribute to find. Looking for ‘ami’:
find_deferred(:environment, :role, :ami)
First checks at @caesars_properties[:environment][:role][:ami] Then, @caesars_properties[:environment][:ami] Finally, @caesars_properties[:ami]
If the last element is an Array, it‘s assumed that only that combination should be returned.
find_deferred(:environment, :role:, [:disks, '/file/path'])
Search order:
Other nested Arrays are treated special too. We look at the criteria from right to left and remove the first nested element we find.
find_deferred([:region, :zone], :environment, :role, :ami)
Search order:
NOTE: There is a maximum depth of 10.
Returns the attribute if found or nil.
DEPRECATED — use find_deferred
Look for an attribute, bubbling up to the parent if it‘s not found criteria is an array of attribute names, orders according to their relationship. The last element is considered to the desired attribute. It can be an array.
# Looking for 'attribute'. # First checks at @caesars_properties[grandparent][parent][attribute] # Then, @caesars_properties[grandparent][attribute] # Finally, @caesars_properties[attribute] find_deferred('grandparent', 'parent', 'attribute')
Returns the attribute if found or nil.
This method handles all of the attributes that are not forced hashes It‘s used in the DSL for handling attributes dyanamically (that weren‘t defined previously) and also in subclasses of Caesars for returning the appropriate attribute values.