caesars 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,9 +1,15 @@
1
1
  CAESAR -- CHANGES
2
2
 
3
3
 
4
+ #### 0.5.3 (2009-04-10) ###############################
5
+
6
+ * ADDED: Better error handling when reading DSL config files
7
+ * ADDED: forced_hash method
8
+
9
+
4
10
  #### 0.5.2 (2009-03-31) ###############################
5
11
 
6
- * NEW: Caesars.debug?, Caesars.enable_debug, Caesars.disable_debug
12
+ * ADDED: Caesars.debug?, Caesars.enable_debug, Caesars.disable_debug
7
13
  * CHANGED: find_deferred now supports nested Arrays. See rdocs.
8
14
  * BUG: Found bug related to string/symbol ambiguity when using find.
9
15
  It's not fixed yet so for now be mindful of which attributes are
@@ -14,31 +20,31 @@ and method accessors are not affected.
14
20
 
15
21
  #### 0.5.1 (2009-03-11) ###############################
16
22
 
17
- * FIX: Method-syntax was broken for attributes of top level method
18
- * FIX: Caesars::Hash#refresh was setting @options to nil
23
+ * FIXED: Method-syntax was broken for attributes of top level method
24
+ * FIXED: Caesars::Hash#refresh was setting @options to nil
19
25
  * UPDATED: docs and bin/example to reflect Caesars::Hash changes.
20
- * FIX: instance_variables in Ruby 1.9.1 returns Symbols
26
+ * FIXED: instance_variables in Ruby 1.9.1 returns Symbols
21
27
 
22
28
 
23
29
  #### 0.5.0 (2009-03-11) ###############################
24
30
 
25
- * FIX: find_deferred now gracefully handles nil errors
26
- * NEW: empty? method in Caesars::Config
27
- * NEW: post processing hook in Caesars::Config#refresh
28
- * NEW: Caesars::Hash#to_hash now recursively casts children to ::Hash.
29
- * FIX: Added Array support to Caesars::Hash
30
- * NEW: Setters for Caesars attributes
31
- * NEW: Caesars::Config supports multiple config files
32
- * NEW: Top level methods used more than once now merges values
31
+ * FIXED: find_deferred now gracefully handles nil errors
32
+ * ADDED: empty? method in Caesars::Config
33
+ * ADDED: post processing hook in Caesars::Config#refresh
34
+ * ADDED: Caesars::Hash#to_hash now recursively casts children to ::Hash.
35
+ * FIXED: Added Array support to Caesars::Hash
36
+ * ADDED: Setters for Caesars attributes
37
+ * ADDED: Caesars::Config supports multiple config files
38
+ * ADDED: Top level methods used more than once now merges values
33
39
  rather than overwrites.
34
- * NEW: Caesars::Config supports reloading config files on the fly
40
+ * ADDED: Caesars::Config supports reloading config files on the fly
35
41
 
36
42
 
37
43
  #### 0.4.2 (2009-03-05) ###############################
38
44
 
39
- * FIX: missing bin/party.conf in gem release
40
- * FIX: Now works with Ruby 1.8+
41
- * NEW: Cleaner rdocs.
45
+ * FIXED: missing bin/party.conf in gem release
46
+ * FIXED: Now works with Ruby 1.8+
47
+ * ADDED: Cleaner rdocs.
42
48
  * TODO: Fix support for top level methods with names:
43
49
  food :extra do; end; # => food_extra
44
50
 
@@ -47,18 +53,18 @@ food :extra do; end; # => food_extra
47
53
 
48
54
  * CHANGE: Removed bloody method. We now parse blocks immediately.
49
55
  * CHANGE: Renamed virgin method to chill.
50
- * NEW: Caesars::Config class for loading DSLs as config files.
56
+ * ADDED: Caesars::Config class for loading DSLs as config files.
51
57
  See Example 3.
52
- * NEW: Added find_deferred method to automatically jump up the
58
+ * ADDED: Added find_deferred method to automatically jump up the
53
59
  heirarchy when looking for a specific attribute.
54
- * NEW: Added to_hash and [] methods to Caesars to make it
60
+ * ADDED: Added to_hash and [] methods to Caesars to make it
55
61
  more hashlike.
56
- * FIX: "chilled" attributes weren't available by method name
62
+ * FIXED: "chilled" attributes weren't available by method name
57
63
 
58
64
 
59
65
  #### 0.3.2 (2009-03-04) ###############################
60
66
 
61
- * FIX: Added file and line info for eval code (better debugging).
67
+ * FIXED: Added file and line info for eval code (better debugging).
62
68
  * CHANGE: The top level DSL method names are now determined by
63
69
  by the class name. Some::ClassName becomes classname.
64
70
  This is less confusing than allowing it to be anything
@@ -68,9 +74,9 @@ namespace.
68
74
 
69
75
  #### 0.3.1 (2009-03-04) ###############################
70
76
 
71
- * NEW: Accept instances without a name
77
+ * ADDED: Accept instances without a name
72
78
  * CHANGE: Updated examples.
73
- * NEW: More rdocs.
79
+ * ADDED: More rdocs.
74
80
 
75
81
 
76
82
 
data/README.rdoc CHANGED
@@ -56,17 +56,21 @@ Or for GitHub fans:
56
56
  # will be included in the instance variable (@staff_fte).
57
57
  staff :fte do
58
58
  desc 'Our hard-working, "full-time" staff'
59
+
59
60
  location :splashdown do
60
61
  town :tsawwassen
62
+
61
63
  person :steve, :sheila do
62
64
  role :manager
63
65
  end
66
+
64
67
  person :steve do
65
68
  role :cook
66
69
  anger :high
67
70
  hours 25
68
71
  catchphrase "Rah! [strokes goatee]"
69
72
  end
73
+
70
74
  person :sheila do
71
75
  catchphrase "This gravy tastes like food I ate in a Mexican prison."
72
76
  hours rand(20)
@@ -75,6 +79,7 @@ Or for GitHub fans:
75
79
  ("%.2f" % [gumption * self.splashdown.sheila.rate.to_f]).to_f
76
80
  end
77
81
  end
82
+
78
83
  person :delano do
79
84
  role :cook
80
85
  rate "8.35/h"
@@ -82,9 +87,9 @@ Or for GitHub fans:
82
87
  satisfaction :low
83
88
  calculate :salary do
84
89
  self.splashdown.delano.rate.to_f * self.splashdown.delano.hours
85
-
86
90
  end
87
91
  end
92
+
88
93
  end
89
94
  end
90
95
 
@@ -104,7 +109,6 @@ Or for GitHub fans:
104
109
  # You can call them manually and send arguments like you normally would.
105
110
  p @staff_fte.splashdown.delano.salary.call # => 475.95
106
111
  p @staff_fte.splashdown.sheila.salary.call(rand(100)) # => 549.77
107
- p @staff_fte.splashdown.keys
108
112
 
109
113
 
110
114
  == EXAMPLE 3 -- External Config file
@@ -159,9 +163,9 @@ Or for GitHub fans:
159
163
 
160
164
  == Thanks
161
165
 
162
- * Clams, Tomatoes, Vodka, and the rest of the crew.
166
+ * Clams, Tomatoes, Grey Goose, and the rest of the crew.
163
167
  * Caleb Buxton (http://cpb.ca) for early feedback.
164
-
168
+ * Solutious Inc (http://solutious.com)
165
169
 
166
170
  == License
167
171
 
data/bin/example CHANGED
@@ -53,17 +53,21 @@ extend Staff::DSL
53
53
  # will be included in the instance variable (@staff_fte).
54
54
  staff :fte do
55
55
  desc 'Our hard-working, "full-time" staff'
56
+
56
57
  location :splashdown do
57
58
  town :tsawwassen
59
+
58
60
  person :steve, :sheila do
59
61
  role :manager
60
62
  end
63
+
61
64
  person :steve do
62
65
  role :cook
63
66
  anger :high
64
67
  hours 25
65
68
  catchphrase "Rah! [strokes goatee]"
66
69
  end
70
+
67
71
  person :sheila do
68
72
  catchphrase "This gravy tastes like food I ate in a Mexican prison."
69
73
  hours rand(20)
@@ -72,16 +76,17 @@ staff :fte do
72
76
  ("%.2f" % [gumption * self.splashdown.sheila.rate.to_f]).to_f
73
77
  end
74
78
  end
79
+
75
80
  person :delano do
76
81
  role :cook
77
82
  rate "8.35/h"
78
83
  hours 57
79
84
  satisfaction :low
80
85
  calculate :salary do
81
- self.splashdown.delano.rate.to_f * self.splashdown.delano.hours
82
-
86
+ self.splashdown.delano.rate.to_f * self.splashdown.delano.hours
83
87
  end
84
88
  end
89
+
85
90
  end
86
91
  end
87
92
 
@@ -101,7 +106,6 @@ p @staff_fte.splashdown[:steve][:role] # => [:manager, :cook]
101
106
  # You can call them manually and send arguments like you normally would.
102
107
  p @staff_fte.splashdown.delano.salary.call # => 475.95
103
108
  p @staff_fte.splashdown.sheila.salary.call(rand(100)) # => 549.77
104
- p @staff_fte.splashdown.keys
105
109
 
106
110
 
107
111
  # ------------------------------------------------------------------
data/caesars.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = %q{caesars}
3
- s.version = "0.5.2"
4
- s.date = %q{2009-03-31}
3
+ s.version = "0.5.3"
4
+ s.date = %q{2009-04-10}
5
5
  s.specification_version = 1 if s.respond_to? :specification_version=
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
7
 
data/lib/caesars.rb CHANGED
@@ -7,9 +7,9 @@
7
7
  # See bin/example
8
8
  #
9
9
  class Caesars
10
- VERSION = "0.5.2"
10
+ VERSION = "0.5.3"
11
11
  @@debug = false
12
-
12
+
13
13
  def Caesars.enable_debug; @@debug = true; end
14
14
  def Caesars.disable_debug; @@debug = false; end
15
15
  def Caesars.debug?; @@debug; end
@@ -108,21 +108,23 @@ class Caesars
108
108
  # should be returned.
109
109
  #
110
110
  # find_deferred(:environment, :role:, [:disks, '/file/path'])
111
- #
112
- # [:environment][:role][:disks]['/file/path']
113
- # [:environment][:disks]['/file/path']
114
- # [:disks]['/file/path']
111
+ #
112
+ # Search order:
113
+ # * [:environment][:role][:disks]['/file/path']
114
+ # * [:environment][:disks]['/file/path']
115
+ # * [:disks]['/file/path']
115
116
  #
116
117
  # Other nested Arrays are treated special too. We look at the criteria from
117
118
  # right to left and remove the first nested element we find.
118
119
  #
119
120
  # find_deferred([:region, :zone], :environment, :role, :ami)
120
121
  #
121
- # [:region][:zone][:environment][:role][:ami]
122
- # [:region][:environment][:role][:ami]
123
- # [:environment][:role][:ami]
124
- # [:environment][:ami]
125
- # [:ami]
122
+ # Search order:
123
+ # * [:region][:zone][:environment][:role][:ami]
124
+ # * [:region][:environment][:role][:ami]
125
+ # * [:environment][:role][:ami]
126
+ # * [:environment][:ami]
127
+ # * [:ami]
126
128
  #
127
129
  # Returns the attribute if found or nil.
128
130
  #
@@ -136,7 +138,7 @@ class Caesars
136
138
  # i.e. find([1, 2, :attribute])
137
139
  # We don't use flatten b/c we don't want to disturb nested Arrays
138
140
  if criteria.empty?
139
- criteria = att
141
+ criteria = attribute
140
142
  att = criteria.pop
141
143
  end
142
144
 
@@ -144,7 +146,6 @@ class Caesars
144
146
  sacrifice = nil
145
147
 
146
148
  while !criteria.empty?
147
- p [criteria, att].flatten if Caesars.debug?
148
149
  found = find(criteria, att)
149
150
  break if found
150
151
 
@@ -225,7 +226,12 @@ class Caesars
225
226
  #(@caesars_pointer[:"#{meth}_values"] ||= []) << name
226
227
  @caesars_pointer[name] ||= Caesars::Hash.new
227
228
  @caesars_pointer = @caesars_pointer[name]
228
- b.call if b
229
+ begin
230
+ b.call if b
231
+ rescue ArgumentError, SyntaxError => ex
232
+ STDERR.puts "CAESARS: error in #{meth} (#{args.join(', ')})"
233
+ raise ex
234
+ end
229
235
  @caesars_pointer = prev
230
236
  end
231
237
 
@@ -253,7 +259,7 @@ class Caesars
253
259
  # end
254
260
  # end
255
261
  #
256
- # @config.food.order.call(3) # => 5
262
+ # @config.food.count.call(3) # => 5
257
263
  #
258
264
  def self.chill(caesars_meth)
259
265
  module_eval %Q{
@@ -261,7 +267,7 @@ class Caesars
261
267
  # caesars.toplevel.unnamed_chilled_attribute
262
268
  return @caesars_properties[:'#{caesars_meth}'] if @caesars_properties.has_key?(:'#{caesars_meth}') && caesars_names.empty? && b.nil?
263
269
 
264
- # Use the name of the bloody method if no name is supplied.
270
+ # Use the name of the chilled method if no name is supplied.
265
271
  caesars_names << :'#{caesars_meth}' if caesars_names.empty?
266
272
 
267
273
  caesars_names.each do |name|
@@ -275,6 +281,46 @@ class Caesars
275
281
  end
276
282
 
277
283
 
284
+
285
+ # Force the specified keyword to always be treated as a hash.
286
+ # Example:
287
+ #
288
+ # startup do
289
+ # disks do
290
+ # create "/path/2" # Available as hash: [action][disks][create][/path/2] == {}
291
+ # create "/path/4" do # Available as hash: [action][disks][create][/path/4] == {size => 14}
292
+ # size 14
293
+ # end
294
+ # end
295
+ # end
296
+ #
297
+ def self.forced_hash(caesars_meth, &b)
298
+ module_eval %Q{
299
+ def #{caesars_meth}(*caesars_names,&b)
300
+ if @caesars_properties.has_key?(:'#{caesars_meth}') && caesars_names.empty? && b.nil?
301
+ return @caesars_properties[:'#{caesars_meth}']
302
+ end
303
+
304
+ return nil if caesars_names.empty? && b.nil?
305
+ return method_missing(:'#{caesars_meth}', *caesars_names, &b) if caesars_names.empty?
306
+
307
+ caesars_name = caesars_names.shift
308
+
309
+ prev = @caesars_pointer
310
+ @caesars_pointer[:'#{caesars_meth}'] ||= Caesars::Hash.new
311
+ hash = Caesars::Hash.new
312
+ @caesars_pointer = hash
313
+ b.call if b
314
+ @caesars_pointer = prev
315
+ @caesars_pointer[:'#{caesars_meth}'][caesars_name] = hash
316
+ @caesars_pointer = prev
317
+ end
318
+ }
319
+ nil
320
+
321
+
322
+ end
323
+
278
324
  # Executes automatically when Caesars is subclassed. This creates the
279
325
  # YourClass::DSL module which contains a single method named after YourClass
280
326
  # that is used to catch the top level DSL method.
@@ -350,7 +396,7 @@ class Caesars::Config
350
396
  refresh
351
397
  end
352
398
 
353
- def init
399
+ def caesars_init
354
400
  # Remove instance variables used to populate DSL data
355
401
  instance_variables.each do |varname|
356
402
  next if varname == :'@options' || varname == :'@paths' # Ruby 1.9.1
@@ -373,7 +419,7 @@ class Caesars::Config
373
419
  end
374
420
 
375
421
  def refresh
376
- init
422
+ caesars_init
377
423
 
378
424
  @paths.each do |path|
379
425
  puts "Loading config from #{path}" if @verbose
@@ -390,9 +436,10 @@ class Caesars::Config
390
436
 
391
437
  postprocess
392
438
 
393
- rescue SyntaxError => ex
439
+ rescue ArgumentError, SyntaxError => ex
394
440
  puts "Syntax error in #{path}."
395
441
  puts ex.message
442
+ puts ex.backtrace if Caesars.debug?
396
443
  exit 1
397
444
  end
398
445
  end
@@ -429,5 +476,3 @@ end
429
476
 
430
477
 
431
478
 
432
-
433
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caesars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-31 00:00:00 -04:00
12
+ date: 2009-04-10 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15