Module: Merb::Inspector::Manager
- Defined in:
- lib/merb_inspector/manager.rb
Class Attribute Summary collapse
-
.caches ⇒ Object
Returns the value of attribute caches.
-
.stores ⇒ Object
Returns the value of attribute stores.
Class Method Summary collapse
-
.install ⇒ Object
Install.
- .load_builtin_inspectors ⇒ Object
- .log(message) ⇒ Object
- .lookup(object) ⇒ Object
- .mirror(dir) ⇒ Object
- .register(klass, inspector) ⇒ Object
- .reset ⇒ Object
Class Attribute Details
.caches ⇒ Object
Returns the value of attribute caches.
9 10 11 |
# File 'lib/merb_inspector/manager.rb', line 9 def caches @caches end |
.stores ⇒ Object
Returns the value of attribute stores.
8 9 10 |
# File 'lib/merb_inspector/manager.rb', line 8 def stores @stores end |
Class Method Details
.install ⇒ Object
Install
66 67 68 |
# File 'lib/merb_inspector/manager.rb', line 66 def self.install mirror("public/stylesheets") end |
.load_builtin_inspectors ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/merb_inspector/manager.rb', line 21 def self.load_builtin_inspectors inspector_dir = File.dirname(__FILE__) / "../../inspectors" Dir["#{inspector_dir}/*.rb"].sort.each do |file| begin require file rescue Exception => error = "[MerbInspector] load error: #{error} (#{error.class})\n#{error.backtraces.first rescue nil}" Merb.logger.error end end end |
.log(message) ⇒ Object
33 34 35 36 37 |
# File 'lib/merb_inspector/manager.rb', line 33 def self.log() path = Merb.root / "log" / "inspector.log" = "[Inspector] %s" % .to_s.strip File.open(path, "a+") {|f| f.puts } end |
.lookup(object) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/merb_inspector/manager.rb', line 45 def self.lookup(object) if caches.has_key?(object.class) log "lookup: %s => %s (cached)" % [object.class, caches[object.class] || 'nil'] return caches[object.class] end klass = object.class.ancestors.find{|klass| log "lookup: %s = %s ... %s" % [object.class, klass, stores[klass]] stores.has_key?(klass) } caches[object.class] = stores[klass] if klass log "lookup: %s => %s (registered)" % [object.class, caches[object.class]] else log "lookup: %s => nil (registered as negative cache)" % [object.class] end return stores[klass] end |
.mirror(dir) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/merb_inspector/manager.rb', line 70 def self.mirror(dir) source_dir = File.join(File.dirname(__FILE__), '..', '..', 'mirror', dir) target_dir = File.join(Merb.root, dir) FileUtils.mkdir_p(target_dir) unless File.exist?(target_dir) Dir[source_dir + "/*"].each do |src| time = File.mtime(src) file = File.basename(src) dst = File.join(target_dir, file) next if File.directory?(src) next if File.exist?(dst) and File.mtime(dst) >= time FileUtils.copy(src, dst) File.utime(time, time, dst) command = File.exist?(dst) ? "update" : "install" log "#{command}: #{dir}/#{file}" end end |
.register(klass, inspector) ⇒ Object
39 40 41 42 43 |
# File 'lib/merb_inspector/manager.rb', line 39 def self.register(klass, inspector) raise "#{klass} inspector already setup" if stores.has_key?(klass) stores[klass] = inspector log "registered %s -> %s" % [klass, inspector] end |
.reset ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/merb_inspector/manager.rb', line 12 def self.reset self.stores = Hash.new self.caches = Hash.new log = Merb.root / "log" / "inspector.log" File.unlink log if File.exist?(log) load_builtin_inspectors end |