Class: Mote
- Inherits:
-
Object
- Object
- Mote
- Defined in:
- lib/mote/debug.rb
Overview
This mote plugin is meant to be used only during development, to help with debugging errors.
You debug errors by checking out:
tmp/cache/mote/*.mote.rb
The files written here are compiled, and you can explore how mote actually writes them. When you run into an error, the browser reports the line number in these files. From there you can check the actual offending line in the compiled mote file.
Class Method Summary collapse
- .cache(data) {|path| ... } ⇒ Object
-
.cache_path(*args) ⇒ Object
The default cache path is in your project /tmp folder.
-
.compile(context, parts) ⇒ Object
This overrides the standard ‘Mote::compile` method by writing the compiled form into a file, and passing the filename into instance_eval.
- .write(path, parts) ⇒ Object
Class Method Details
.cache(data) {|path| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mote/debug.rb', line 30 def self.cache(data) # First we write the generated the filename using the MD5 # of the data. This prevents us from re-writing them if # ever we've already done so. path = cache_path(Digest::MD5.hexdigest(data) + ".mote.rb") # Now we can write the file into the specified path, if # it doesn't exist yet. write(path, data) unless File.exist?(path) yield path end |
.cache_path(*args) ⇒ Object
The default cache path is in your project /tmp folder.
44 45 46 |
# File 'lib/mote/debug.rb', line 44 def self.cache_path(*args) File.join(Dir.pwd, "tmp/cache/mote", *args) end |
.compile(context, parts) ⇒ Object
This overrides the standard ‘Mote::compile` method by writing the compiled form into a file, and passing the filename into instance_eval. That way errors can be properly traced back to the actual offending line.
22 23 24 25 26 27 28 |
# File 'lib/mote/debug.rb', line 22 def self.compile(context, parts) FileUtils.mkdir_p(cache_path) unless File.directory?(cache_path) cache(parts) do |path| context.instance_eval(parts, path, 1) end end |
.write(path, parts) ⇒ Object
48 49 50 |
# File 'lib/mote/debug.rb', line 48 def self.write(path, parts) File.open(path, "w") { |f| f.write(parts) } end |