delano-caesars 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.txt +35 -23
- data/README.rdoc +6 -2
- data/bin/example +7 -3
- data/caesars.gemspec +2 -2
- data/lib/caesars.rb +74 -26
- metadata +2 -2
data/CHANGES.txt
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
CAESAR -- CHANGES
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
#### 0.5.4 (2009-04-11) ###############################
|
|
5
|
+
|
|
6
|
+
* FIXED: find_deferred would abort early because the safety limit
|
|
7
|
+
to prevent endless loops wasn't being reset between calls.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
#### 0.5.3 (2009-04-10) ###############################
|
|
11
|
+
|
|
12
|
+
* ADDED: Better error handling when reading DSL config files
|
|
13
|
+
* ADDED: forced_hash method
|
|
14
|
+
|
|
15
|
+
|
|
4
16
|
#### 0.5.2 (2009-03-31) ###############################
|
|
5
17
|
|
|
6
|
-
*
|
|
18
|
+
* ADDED: Caesars.debug?, Caesars.enable_debug, Caesars.disable_debug
|
|
7
19
|
* CHANGED: find_deferred now supports nested Arrays. See rdocs.
|
|
8
20
|
* BUG: Found bug related to string/symbol ambiguity when using find.
|
|
9
21
|
It's not fixed yet so for now be mindful of which attributes are
|
|
@@ -14,31 +26,31 @@ and method accessors are not affected.
|
|
|
14
26
|
|
|
15
27
|
#### 0.5.1 (2009-03-11) ###############################
|
|
16
28
|
|
|
17
|
-
*
|
|
18
|
-
*
|
|
29
|
+
* FIXED: Method-syntax was broken for attributes of top level method
|
|
30
|
+
* FIXED: Caesars::Hash#refresh was setting @options to nil
|
|
19
31
|
* UPDATED: docs and bin/example to reflect Caesars::Hash changes.
|
|
20
|
-
*
|
|
32
|
+
* FIXED: instance_variables in Ruby 1.9.1 returns Symbols
|
|
21
33
|
|
|
22
34
|
|
|
23
35
|
#### 0.5.0 (2009-03-11) ###############################
|
|
24
36
|
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
37
|
+
* FIXED: find_deferred now gracefully handles nil errors
|
|
38
|
+
* ADDED: empty? method in Caesars::Config
|
|
39
|
+
* ADDED: post processing hook in Caesars::Config#refresh
|
|
40
|
+
* ADDED: Caesars::Hash#to_hash now recursively casts children to ::Hash.
|
|
41
|
+
* FIXED: Added Array support to Caesars::Hash
|
|
42
|
+
* ADDED: Setters for Caesars attributes
|
|
43
|
+
* ADDED: Caesars::Config supports multiple config files
|
|
44
|
+
* ADDED: Top level methods used more than once now merges values
|
|
33
45
|
rather than overwrites.
|
|
34
|
-
*
|
|
46
|
+
* ADDED: Caesars::Config supports reloading config files on the fly
|
|
35
47
|
|
|
36
48
|
|
|
37
49
|
#### 0.4.2 (2009-03-05) ###############################
|
|
38
50
|
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
51
|
+
* FIXED: missing bin/party.conf in gem release
|
|
52
|
+
* FIXED: Now works with Ruby 1.8+
|
|
53
|
+
* ADDED: Cleaner rdocs.
|
|
42
54
|
* TODO: Fix support for top level methods with names:
|
|
43
55
|
food :extra do; end; # => food_extra
|
|
44
56
|
|
|
@@ -47,18 +59,18 @@ food :extra do; end; # => food_extra
|
|
|
47
59
|
|
|
48
60
|
* CHANGE: Removed bloody method. We now parse blocks immediately.
|
|
49
61
|
* CHANGE: Renamed virgin method to chill.
|
|
50
|
-
*
|
|
62
|
+
* ADDED: Caesars::Config class for loading DSLs as config files.
|
|
51
63
|
See Example 3.
|
|
52
|
-
*
|
|
64
|
+
* ADDED: Added find_deferred method to automatically jump up the
|
|
53
65
|
heirarchy when looking for a specific attribute.
|
|
54
|
-
*
|
|
66
|
+
* ADDED: Added to_hash and [] methods to Caesars to make it
|
|
55
67
|
more hashlike.
|
|
56
|
-
*
|
|
68
|
+
* FIXED: "chilled" attributes weren't available by method name
|
|
57
69
|
|
|
58
70
|
|
|
59
71
|
#### 0.3.2 (2009-03-04) ###############################
|
|
60
72
|
|
|
61
|
-
*
|
|
73
|
+
* FIXED: Added file and line info for eval code (better debugging).
|
|
62
74
|
* CHANGE: The top level DSL method names are now determined by
|
|
63
75
|
by the class name. Some::ClassName becomes classname.
|
|
64
76
|
This is less confusing than allowing it to be anything
|
|
@@ -68,9 +80,9 @@ namespace.
|
|
|
68
80
|
|
|
69
81
|
#### 0.3.1 (2009-03-04) ###############################
|
|
70
82
|
|
|
71
|
-
*
|
|
83
|
+
* ADDED: Accept instances without a name
|
|
72
84
|
* CHANGE: Updated examples.
|
|
73
|
-
*
|
|
85
|
+
* ADDED: More rdocs.
|
|
74
86
|
|
|
75
87
|
|
|
76
88
|
|
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
|
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.
|
|
4
|
-
s.date = %q{2009-
|
|
3
|
+
s.version = "0.5.4"
|
|
4
|
+
s.date = %q{2009-04-11}
|
|
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.
|
|
10
|
+
VERSION = "0.5.4"
|
|
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,30 +108,35 @@ class Caesars
|
|
|
108
108
|
# should be returned.
|
|
109
109
|
#
|
|
110
110
|
# find_deferred(:environment, :role:, [:disks, '/file/path'])
|
|
111
|
-
#
|
|
112
|
-
#
|
|
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
|
-
#
|
|
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]
|
|
128
|
+
#
|
|
129
|
+
# NOTE: There is a maximum depth of 10.
|
|
126
130
|
#
|
|
127
131
|
# Returns the attribute if found or nil.
|
|
128
132
|
#
|
|
129
133
|
def find_deferred(*criteria)
|
|
134
|
+
|
|
130
135
|
# The last element is assumed to be the attribute we're looking for.
|
|
131
136
|
# The purpose of this function is to bubble up the hierarchy of a
|
|
132
137
|
# hash to find it.
|
|
133
138
|
att = criteria.pop
|
|
134
|
-
|
|
139
|
+
|
|
135
140
|
# Account for everything being sent as an Array
|
|
136
141
|
# i.e. find([1, 2, :attribute])
|
|
137
142
|
# We don't use flatten b/c we don't want to disturb nested Arrays
|
|
@@ -139,12 +144,11 @@ class Caesars
|
|
|
139
144
|
criteria = att
|
|
140
145
|
att = criteria.pop
|
|
141
146
|
end
|
|
142
|
-
|
|
147
|
+
|
|
143
148
|
found = nil
|
|
144
149
|
sacrifice = nil
|
|
145
|
-
|
|
150
|
+
|
|
146
151
|
while !criteria.empty?
|
|
147
|
-
p [criteria, att].flatten if Caesars.debug?
|
|
148
152
|
found = find(criteria, att)
|
|
149
153
|
break if found
|
|
150
154
|
|
|
@@ -166,9 +170,8 @@ class Caesars
|
|
|
166
170
|
|
|
167
171
|
# We need to make a sacrifice
|
|
168
172
|
sacrifice = criteria.pop if sacrifice.nil?
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
@limit += 1
|
|
173
|
+
break if (limit ||= 0) > 10 # A failsafe
|
|
174
|
+
limit += 1
|
|
172
175
|
sacrifice = nil
|
|
173
176
|
end
|
|
174
177
|
|
|
@@ -225,7 +228,12 @@ class Caesars
|
|
|
225
228
|
#(@caesars_pointer[:"#{meth}_values"] ||= []) << name
|
|
226
229
|
@caesars_pointer[name] ||= Caesars::Hash.new
|
|
227
230
|
@caesars_pointer = @caesars_pointer[name]
|
|
228
|
-
|
|
231
|
+
begin
|
|
232
|
+
b.call if b
|
|
233
|
+
rescue ArgumentError, SyntaxError => ex
|
|
234
|
+
STDERR.puts "CAESARS: error in #{meth} (#{args.join(', ')})"
|
|
235
|
+
raise ex
|
|
236
|
+
end
|
|
229
237
|
@caesars_pointer = prev
|
|
230
238
|
end
|
|
231
239
|
|
|
@@ -253,7 +261,7 @@ class Caesars
|
|
|
253
261
|
# end
|
|
254
262
|
# end
|
|
255
263
|
#
|
|
256
|
-
# @config.food.
|
|
264
|
+
# @config.food.count.call(3) # => 5
|
|
257
265
|
#
|
|
258
266
|
def self.chill(caesars_meth)
|
|
259
267
|
module_eval %Q{
|
|
@@ -261,7 +269,7 @@ class Caesars
|
|
|
261
269
|
# caesars.toplevel.unnamed_chilled_attribute
|
|
262
270
|
return @caesars_properties[:'#{caesars_meth}'] if @caesars_properties.has_key?(:'#{caesars_meth}') && caesars_names.empty? && b.nil?
|
|
263
271
|
|
|
264
|
-
# Use the name of the
|
|
272
|
+
# Use the name of the chilled method if no name is supplied.
|
|
265
273
|
caesars_names << :'#{caesars_meth}' if caesars_names.empty?
|
|
266
274
|
|
|
267
275
|
caesars_names.each do |name|
|
|
@@ -275,6 +283,46 @@ class Caesars
|
|
|
275
283
|
end
|
|
276
284
|
|
|
277
285
|
|
|
286
|
+
|
|
287
|
+
# Force the specified keyword to always be treated as a hash.
|
|
288
|
+
# Example:
|
|
289
|
+
#
|
|
290
|
+
# startup do
|
|
291
|
+
# disks do
|
|
292
|
+
# create "/path/2" # Available as hash: [action][disks][create][/path/2] == {}
|
|
293
|
+
# create "/path/4" do # Available as hash: [action][disks][create][/path/4] == {size => 14}
|
|
294
|
+
# size 14
|
|
295
|
+
# end
|
|
296
|
+
# end
|
|
297
|
+
# end
|
|
298
|
+
#
|
|
299
|
+
def self.forced_hash(caesars_meth, &b)
|
|
300
|
+
module_eval %Q{
|
|
301
|
+
def #{caesars_meth}(*caesars_names,&b)
|
|
302
|
+
if @caesars_properties.has_key?(:'#{caesars_meth}') && caesars_names.empty? && b.nil?
|
|
303
|
+
return @caesars_properties[:'#{caesars_meth}']
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
return nil if caesars_names.empty? && b.nil?
|
|
307
|
+
return method_missing(:'#{caesars_meth}', *caesars_names, &b) if caesars_names.empty?
|
|
308
|
+
|
|
309
|
+
caesars_name = caesars_names.shift
|
|
310
|
+
|
|
311
|
+
prev = @caesars_pointer
|
|
312
|
+
@caesars_pointer[:'#{caesars_meth}'] ||= Caesars::Hash.new
|
|
313
|
+
hash = Caesars::Hash.new
|
|
314
|
+
@caesars_pointer = hash
|
|
315
|
+
b.call if b
|
|
316
|
+
@caesars_pointer = prev
|
|
317
|
+
@caesars_pointer[:'#{caesars_meth}'][caesars_name] = hash
|
|
318
|
+
@caesars_pointer = prev
|
|
319
|
+
end
|
|
320
|
+
}
|
|
321
|
+
nil
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
end
|
|
325
|
+
|
|
278
326
|
# Executes automatically when Caesars is subclassed. This creates the
|
|
279
327
|
# YourClass::DSL module which contains a single method named after YourClass
|
|
280
328
|
# that is used to catch the top level DSL method.
|
|
@@ -312,6 +360,7 @@ class Caesars
|
|
|
312
360
|
|
|
313
361
|
end
|
|
314
362
|
}, __FILE__, __LINE__
|
|
363
|
+
|
|
315
364
|
end
|
|
316
365
|
|
|
317
366
|
end
|
|
@@ -350,7 +399,7 @@ class Caesars::Config
|
|
|
350
399
|
refresh
|
|
351
400
|
end
|
|
352
401
|
|
|
353
|
-
def
|
|
402
|
+
def caesars_init
|
|
354
403
|
# Remove instance variables used to populate DSL data
|
|
355
404
|
instance_variables.each do |varname|
|
|
356
405
|
next if varname == :'@options' || varname == :'@paths' # Ruby 1.9.1
|
|
@@ -373,7 +422,7 @@ class Caesars::Config
|
|
|
373
422
|
end
|
|
374
423
|
|
|
375
424
|
def refresh
|
|
376
|
-
|
|
425
|
+
caesars_init
|
|
377
426
|
|
|
378
427
|
@paths.each do |path|
|
|
379
428
|
puts "Loading config from #{path}" if @verbose
|
|
@@ -390,9 +439,10 @@ class Caesars::Config
|
|
|
390
439
|
|
|
391
440
|
postprocess
|
|
392
441
|
|
|
393
|
-
rescue SyntaxError => ex
|
|
442
|
+
rescue ArgumentError, SyntaxError => ex
|
|
394
443
|
puts "Syntax error in #{path}."
|
|
395
444
|
puts ex.message
|
|
445
|
+
puts ex.backtrace if Caesars.debug?
|
|
396
446
|
exit 1
|
|
397
447
|
end
|
|
398
448
|
end
|
|
@@ -429,5 +479,3 @@ end
|
|
|
429
479
|
|
|
430
480
|
|
|
431
481
|
|
|
432
|
-
|
|
433
|
-
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: delano-caesars
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.4
|
|
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-
|
|
12
|
+
date: 2009-04-11 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|