caesars 0.6.0 → 0.6.1

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.
Files changed (4) hide show
  1. data/CHANGES.txt +4 -0
  2. data/caesars.gemspec +1 -2
  3. data/lib/caesars.rb +59 -14
  4. metadata +2 -2
data/CHANGES.txt CHANGED
@@ -1,6 +1,10 @@
1
1
  CAESARS -- CHANGES
2
2
 
3
3
 
4
+ #### 0.6.1 (2009-05-02) ###############################
5
+
6
+ * ADDED: known_symbol? and known_symbol_by_glass?
7
+
4
8
  #### 0.6.0 (2009-04-30) ###############################
5
9
 
6
10
  * ADDED: Forced reloading for Caesars::Config.refresh. This allows
data/caesars.gemspec CHANGED
@@ -1,8 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "caesars"
3
3
  s.rubyforge_project = "caesars"
4
- s.version = "0.6.0"
5
- s.date = "2009-04-30"
4
+ s.version = "0.6.1"
6
5
  s.specification_version = 1 if s.respond_to? :specification_version=
7
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
7
 
data/lib/caesars.rb CHANGED
@@ -12,6 +12,8 @@ class Caesars
12
12
  @@chilled = {}
13
13
  @@forced_array = {}
14
14
  @@forced_ignore = {}
15
+ @@known_symbols = []
16
+ @@known_symbols_by_glass = {}
15
17
 
16
18
  def Caesars.enable_debug; @@debug = true; end
17
19
  def Caesars.disable_debug; @@debug = false; end
@@ -35,6 +37,24 @@ class Caesars
35
37
  @@forced_ignore.has_key?(name.to_sym)
36
38
  end
37
39
 
40
+ # Add +s+ to the list of global symbols (across all instances of Caesars)
41
+ def Caesars.add_known_symbol(g, s)
42
+ g = Caesars.glass(g)
43
+ STDERR.puts "add_symbol: #{g} => #{s}" if Caesars.debug?
44
+ @@known_symbols << s.to_sym
45
+ @@known_symbols_by_glass[g] ||= []
46
+ @@known_symbols_by_glass[g] << s.to_sym
47
+ end
48
+
49
+ # Is +s+ in the global keyword list? (accross all instances of Caesars)
50
+ def Caesars.known_symbol?(s); @@known_symbols.member?(s.to_sym); end
51
+ # Is +s+ in the keyword list for glass +g+?
52
+ def Caesars.known_symbol_by_glass?(g, s)
53
+ g &&= g.to_sym
54
+ @@known_symbols_by_glass[g] ||= []
55
+ @@known_symbols_by_glass[g].member?(s.to_sym)
56
+ end
57
+
38
58
  # A subclass of ::Hash that provides method names for hash parameters.
39
59
  # It's like a lightweight OpenStruct.
40
60
  # ch = Caesars::Hash[:tabasco => :lots!]
@@ -79,14 +99,11 @@ class Caesars
79
99
  init if respond_to?(:init)
80
100
  end
81
101
 
82
- # Returns an array of the available
83
- def keys
84
- @caesars_properties.keys
85
- end
102
+ # Returns an array of the available top-level attributes
103
+ def keys; @caesars_properties.keys; end
86
104
 
87
- def to_hash
88
- @caesars_properties.to_hash
89
- end
105
+ # Returns the parsed tree as a regular hash (instead of a Caesars::Hash)
106
+ def to_hash; @caesars_properties.to_hash; end
90
107
 
91
108
  # DEPRECATED -- use find_deferred
92
109
  #
@@ -233,11 +250,31 @@ class Caesars
233
250
  @caesars_properties[name] = value
234
251
  end
235
252
 
253
+ # Add +keyword+ to the list of known symbols for this instances
254
+ # as well as to the master known symbols list. See: known_symbol?
255
+ def add_known_symbol(s)
256
+ @@known_symbols << s.to_sym
257
+ @@known_symbols_by_glass[glass] ||= []
258
+ @@known_symbols_by_glass[glass] << s.to_sym
259
+ end
260
+
261
+ # Has +s+ already appeared as a keyword in the DSL for this glass type?
262
+ def known_symbol?(s)
263
+ @@known_symbols_by_glass[glass] && @@known_symbols_by_glass[glass].member?(s)
264
+ end
265
+
266
+ # Returns the lowercase name of the class. i.e. Some::Taste # => taste
267
+ def glass; @glass ||= (self.class.to_s.split(/::/))[-1].downcase.to_sym; end
268
+
269
+ # Returns the lowercase name of +klass+. i.e. Some::Taste # => taste
270
+ def self.glass(klass); (klass.to_s.split(/::/))[-1].downcase.to_sym; end
271
+
236
272
  # This method handles all of the attributes that are not forced hashes
237
273
  # It's used in the DSL for handling attributes dyanamically (that weren't defined
238
274
  # previously) and also in subclasses of Caesars for returning the appropriate
239
275
  # attribute values.
240
276
  def method_missing(meth, *args, &b)
277
+ add_known_symbol(meth)
241
278
  if Caesars.forced_ignore?(meth)
242
279
  STDERR.puts "Forced ignore: #{meth}" if Caesars.debug?
243
280
  return
@@ -322,9 +359,12 @@ class Caesars
322
359
  # end
323
360
  #
324
361
  def self.forced_hash(caesars_meth, &b)
362
+ STDERR.puts "forced_hash: #{caesars_meth}" if Caesars.debug?
363
+ Caesars.add_known_symbol(self, caesars_meth)
325
364
  module_eval %Q{
326
365
  def #{caesars_meth}(*caesars_names,&b)
327
366
  this_meth = :'#{caesars_meth}'
367
+ add_known_symbol(this_meth)
328
368
  if Caesars.forced_ignore?(this_meth)
329
369
  STDERR.puts "Forced ignore: \#{this_meth}" if Caesars.debug?
330
370
  return
@@ -380,6 +420,8 @@ class Caesars
380
420
  # @food.count.call(3) # => 5
381
421
  #
382
422
  def self.chill(caesars_meth)
423
+ STDERR.puts "chill: #{caesars_meth}" if Caesars.debug?
424
+ Caesars.add_known_symbol(self, caesars_meth)
383
425
  @@chilled[caesars_meth.to_sym] = true
384
426
  nil
385
427
  end
@@ -401,6 +443,7 @@ class Caesars
401
443
  #
402
444
  def self.forced_array(caesars_meth)
403
445
  STDERR.puts "forced_array: #{caesars_meth}" if Caesars.debug?
446
+ Caesars.add_known_symbol(self, caesars_meth)
404
447
  @@forced_array[caesars_meth.to_sym] = true
405
448
  nil
406
449
  end
@@ -420,6 +463,7 @@ class Caesars
420
463
  #
421
464
  def self.forced_ignore(caesars_meth)
422
465
  STDERR.puts "forced_ignore: #{caesars_meth}" if Caesars.debug?
466
+ Caesars.add_known_symbol(self, caesars_meth)
423
467
  @@forced_ignore[caesars_meth.to_sym] = true
424
468
  nil
425
469
  end
@@ -438,6 +482,7 @@ class Caesars
438
482
  def self.inherited(modname)
439
483
  # NOTE: We may be able to replace this without an eval using Module.nesting
440
484
  meth = (modname.to_s.split(/::/))[-1].downcase # Some::HighBall => highball
485
+ Caesars.add_known_symbol(meth, meth)
441
486
  module_eval %Q{
442
487
  module #{modname}::DSL
443
488
  def #{meth}(*args, &b)
@@ -550,7 +595,9 @@ class Caesars::Config
550
595
  @@glasses.each { |glass| extend glass }
551
596
 
552
597
  begin
598
+ current_path = nil # used in error messages
553
599
  @paths.each do |path|
600
+ current_path = path
554
601
  puts "Loading config from #{path}" if @verbose || Caesars.debug?
555
602
  dsl = File.read path
556
603
  # eval so the DSL code can be executed in this namespace.
@@ -568,14 +615,12 @@ class Caesars::Config
568
615
  STDERR.puts ex.message if Caesars.debug?
569
616
  refresh
570
617
 
571
- rescue Caesars::Error => ex
572
- STDERR.puts ex.message
573
- STDERR.puts ex.backtrace if Caesars.debug?
618
+ #rescue Caesars::Error => ex
619
+ # STDERR.puts ex.message
620
+ # STDERR.puts ex.backtrace if Caesars.debug?
574
621
  rescue ArgumentError, SyntaxError => ex
575
- STDERR.puts "Syntax error in #{path}."
576
- STDERR.puts ex.message
577
- STDERR.puts ex.backtrace if Caesars.debug?
578
- exit 1
622
+ STDERR.puts "Syntax error in #{current_path}."
623
+ raise ex
579
624
  end
580
625
  end
581
626
 
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.6.0
4
+ version: 0.6.1
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-04-30 00:00:00 -04:00
12
+ date: 2009-05-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15