class Filewatcher::Matrix
Spawn Filewatchers from file with path-command matrix
Constants
- VERSION
Public Class Methods
new(path)
click to toggle source
Initialize Filewatcher
instances without any actions @param path [String] the path of YAML file, relative to the current working directory
or can be absolute
# 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
Public Instance Methods
start()
click to toggle source
Spawn Threads with active Filewatchers and execute commands on changes
# 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