Class: Opi::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/opi/loader.rb

Class Method Summary collapse

Class Method Details

.funkyload(file) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/opi/loader.rb', line 10

def funkyload(file)
  begin
    if cache = loadcache[file]
      return if ENV['RACK_ENV'] == 'production'

      if (mtime = File.mtime(file)) > cache
        puts "[Opi::Loader]".green + " reloading: #{file}"
        load file
        loadcache[file] = mtime
      end
    else
      puts "[Opi::Loader]".green + " loading: #{file}"
      load file
      loadcache[file] = File.mtime(file)
    end
  rescue Exception => e
    puts "[Opi::Loader] Exception loading class [#{file}]: #{e.message}"
    puts e.backtrace.join("\n")
    raise e
  end
end

.loadcacheObject



6
7
8
# File 'lib/opi/loader.rb', line 6

def loadcache()
  @loadcache ||= {}
end

.reload!Object



32
33
34
# File 'lib/opi/loader.rb', line 32

def reload!
  Dir["#{@prefix}app/**/*.rb"].each { |x| funkyload x }
end