Class: Filewatcher::Matrix

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(path) ⇒ Matrix

Initialize Filewatcher instances without any actions

Parameters:

  • path (String)

    the path of YAML file, relative to the current working directory or can be absolute



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

#startObject

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