Class: Filewatcher::Matrix
- Inherits:
-
Object
- Object
- Filewatcher::Matrix
- Defined in:
- lib/filewatcher/matrix.rb,
lib/filewatcher/matrix/version.rb
Overview
Spawn Filewatchers from file with path-command matrix
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Method Summary collapse
-
#initialize(path) ⇒ Matrix
constructor
Initialize Filewatcher instances without any actions.
-
#start ⇒ Object
Spawn Threads with active Filewatchers and execute commands on changes.
Constructor Details
#initialize(path) ⇒ Matrix
Initialize Filewatcher instances without any actions
14 15 16 17 18 19 20 21 |
# File 'lib/filewatcher/matrix.rb', line 14 def initialize(path) @filewatchers = YAML.load_file(path).map! do |args| { filewatcher: Filewatcher.new(args.fetch(:pattern), exclude: args[:exclude]), command: args.fetch(:command) } end end |
Instance Method Details
#start ⇒ Object
Spawn Threads with active Filewatchers and execute commands on changes
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/filewatcher/matrix.rb', line 24 def start @filewatchers.map do |hash| Thread.new do command = hash[:command] hash[:filewatcher].watch do |_changes| puts "> #{command}" system command end end end.each(&:join) end |