lib/caboodle/kit.rb in caboodle-0.1.2 vs lib/caboodle/kit.rb in caboodle-0.1.3

- old
+ new

@@ -25,10 +25,11 @@ Caboodle::Site[k.to_s] = v } rescue puts "Warning! Skipping #{p}" Caboodle::Site.kits.uniq! end def dump_config + puts "Dump config" p = File.expand_path(File.join(Caboodle::App.root,"config","site.yml")) d = Caboodle::Site.clone e = d.to_hash e.delete("required_settings") File.open(p, 'w') {|f| f.write(YAML::dump(e))} @@ -55,20 +56,46 @@ end end Caboodle::Kits end + def unload_kit name + unless name.blank? + kit_name = name.to_s.split("::").last || name + kit_name = kit_name.downcase + puts "Loading Kit: #{kit_name}" + orig = Caboodle.constants + require "caboodle/kits/#{kit_name}/#{kit_name}" rescue puts "Warning! No such kit: #{kit_name}" + added = Caboodle.constants - orig + added.each do |d| + c = Caboodle.const_get(d) + if c.respond_to?(:is_a_caboodle_kit) + c.unregister + end + end + end + Caboodle::Kits + end + def register required_settings.each do |r| unless Caboodle::Site[r] puts "Please set a value for #{r}:" v = STDIN.gets Caboodle::Site[r] = v Caboodle::Kit.dump_config end end + Site.kits << self.to_s.split("::").last + Site.kits.uniq! Caboodle::Kits << self end + + def unregister + Caboodle::Kits.delete(self) + Caboodle::Site.kits.delete(self.to_s) + Caboodle::Kit.dump_config + end def require_all if(Caboodle::Site.kits) Caboodle::Site.kits.each { |k| load_kit k } else \ No newline at end of file