Class: LiveReloader
- Inherits:
-
Object
- Object
- LiveReloader
- Defined in:
- lib/ProMotion/repl/live_reloader.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#path_query ⇒ Object
readonly
Returns the value of attribute path_query.
Instance Method Summary collapse
- #debug? ⇒ Boolean
-
#initialize(path, opts = {}) ⇒ LiveReloader
constructor
A new instance of LiveReloader.
- #stop ⇒ Object
- #watch(&callback) ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ LiveReloader
Returns a new instance of LiveReloader.
4 5 6 7 |
# File 'lib/ProMotion/repl/live_reloader.rb', line 4 def initialize(path, opts={}) @path_query = path @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
2 3 4 |
# File 'lib/ProMotion/repl/live_reloader.rb', line 2 def opts @opts end |
#path_query ⇒ Object (readonly)
Returns the value of attribute path_query.
2 3 4 |
# File 'lib/ProMotion/repl/live_reloader.rb', line 2 def path_query @path_query end |
Instance Method Details
#debug? ⇒ Boolean
35 36 37 |
# File 'lib/ProMotion/repl/live_reloader.rb', line 35 def debug? @opts[:debug] end |
#stop ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ProMotion/repl/live_reloader.rb', line 28 def stop @live_reload_timer.invalidate if @live_reload_timer @live_reload_timer = nil log "Stopped." self end |
#watch(&callback) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ProMotion/repl/live_reloader.rb', line 9 def watch(&callback) log path_query log live_file_paths @live_reload_timer = every(opts[:interval] || 0.5) do live_files.each do |live_file, modified_date| if File.exist?(live_file) && File.mtime(live_file) > modified_date new_code = File.read(live_file) eval(new_code) callback.call *[live_file, new_code, parse_class_names(new_code)].first(callback.arity) reload_live_files end end end log "Watching #{path_query}." self end |