2 BASE_DIR = File.dirname(__FILE__)
5 # load all ruby files in subdirectories
6 Dir[File.join(BASE_DIR, '*')].each do |f|
8 Dir[File.join(f, '*.rb')].each do |rb_file|
15 ObjectSpace::each_object(Class) do |k|
17 @themes[k.theme_name] = k
24 @themes.each_value(&blk)
27 def get(name, game, opts = { })
28 instantiate @themes[name]
31 def get_matching(preferred, game, required, optional, opts = {})
32 pref = @themes[preferred]
33 return instantiate(pref, game, opts) if pref and pref.matches?(required)
35 themes = @themes.values.reject {|x| not x.matches?(required) }.sort_by {|x| x.score(optional) }
37 raise "No valid theme"
39 instantiate themes.last, game, opts
45 def instantiate(theme, game, opts = {})
46 theme.new(opts.merge(:game => game))