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.
- .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
52 53 54 |
# File 'lib/merb_inspector/manager.rb', line 52 def self.install mirror("public/stylesheets") end |
.log(message) ⇒ Object
43 44 45 46 47 |
# File 'lib/merb_inspector/manager.rb', line 43 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/merb_inspector/manager.rb', line 25 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/merb_inspector/manager.rb', line 56 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
19 20 21 22 23 |
# File 'lib/merb_inspector/manager.rb', line 19 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
15 16 17 |
# File 'lib/merb_inspector/manager.rb', line 15 def self.reset self.caches = Hash.new end |