Module: Caboodle::Config

Defined in:
lib/caboodle/config.rb

Class Method Summary collapse

Class Method Details

.load_config(p) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/caboodle/config.rb', line 27

def load_config p
  loaded = YAML.load(p)
  Hashie::Mash.new(loaded).each{ |k,v| 
    v.strip! if v.class == String
    Caboodle::Site[k.to_s] = v } rescue puts "Warning! Skipping #{p}"
  Caboodle::Site.kits.uniq!
end

.load_config_file(p) ⇒ Object



35
36
37
# File 'lib/caboodle/config.rb', line 35

def load_config_file p
  configure_site(open(p).read)
end

.load_kit(name, ask = true) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/caboodle/config.rb', line 52

def load_kit name, ask=true
  unless name.blank?
    kit_name = name.to_s.split("::").last || name
    kit_name = kit_name.downcase
    orig = Caboodle.constants
    begin
      puts "Loading #{kit_name}"
      require "caboodle/kits/#{kit_name}/#{kit_name}"
      added = Caboodle.constants - orig
      added.each do |d| 
        c = Caboodle.const_get(d)
        if c.respond_to?(:is_a_caboodle_kit)
          c.register_kit ask
        end
      end
    rescue Exception=>e
      if ENV["RACK_ENV"] == "production"
        Caboodle::Errors << Hashie::Mash.new({:title=>"Failed to load #{name} kit", :reason=>e.backtrace})
        puts "Failed to load #{name} kit: #{e.backtrace}"
      else
        raise e
      end
    end
  end
  Caboodle::Kits
end

.require_all(ask = true) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/caboodle/config.rb', line 39

def require_all ask=true
  if(Caboodle::Site.kits)
    Caboodle::Site.kits.each { |k| load_kit k, ask }
  else
    STDERR.puts "No kits to register"
  end
  Caboodle::Kits
end

.setupObject



22
23
24
25
# File 'lib/caboodle/config.rb', line 22

def setup
  require_all
  use_all
end

.unload_kit(name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/caboodle/config.rb', line 79

def unload_kit name
  unless name.blank?
    kit_name = name.to_s.split("::").last || name
    kit_name = kit_name.downcase
    puts "Unloading Kit: #{kit_name}"
    orig = Caboodle.constants
    require "caboodle/kits/#{kit_name}/#{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_kit
      end
    end
  end
  Caboodle::Kits
end

.use_allObject



48
49
50
# File 'lib/caboodle/config.rb', line 48

def use_all
  Caboodle::Kits.each { |p| p.start }
end