Class: Gazr::Controller
- Inherits:
-
Object
- Object
- Gazr::Controller
- Defined in:
- lib/gazr/controller.rb
Instance Method Summary collapse
-
#initialize(script, handler) ⇒ Controller
constructor
A new instance of Controller.
- #monitored_paths ⇒ Object
- #run ⇒ Object
- #update(path, event_type = nil) ⇒ Object
Constructor Details
#initialize(script, handler) ⇒ Controller
Returns a new instance of Controller.
3 4 5 6 7 |
# File 'lib/gazr/controller.rb', line 3 def initialize(script, handler) @script, @handler = script, handler @handler.add_observer(self) Gazr.debug "using %s handler" % handler.class.name end |
Instance Method Details
#monitored_paths ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/gazr/controller.rb', line 27 def monitored_paths paths = Dir['**/*'].select do |path| @script.patterns.any? {|p| path.match(p) } end paths.push(@script.path).compact! paths.map {|path| Pathname(path). } end |
#run ⇒ Object
9 10 11 12 13 |
# File 'lib/gazr/controller.rb', line 9 def run @script.parse! @handler.listen(monitored_paths) rescue Interrupt end |
#update(path, event_type = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gazr/controller.rb', line 15 def update(path, event_type = nil) path = Pathname(path). Gazr.debug("received #{event_type.inspect} event for #{path.relative_path_from(Pathname(Dir.pwd))}") if path == @script.path && event_type != :accessed @script.parse! @handler.refresh(monitored_paths) else @script.action_for(path, event_type).call end end |