Class: Kodiak::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/kodiak/watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options) ⇒ Watcher

Returns a new instance of Watcher.



8
9
10
11
12
13
# File 'lib/kodiak/watcher.rb', line 8

def initialize(config, options)
	@config = config
	@files = config.files
	@options = options
	watch
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/kodiak/watcher.rb', line 6

def config
  @config
end

#filesObject

Returns the value of attribute files.



6
7
8
# File 'lib/kodiak/watcher.rb', line 6

def files
  @files
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/kodiak/watcher.rb', line 6

def options
  @options
end

Instance Method Details

#watchObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kodiak/watcher.rb', line 15

def watch
	transporter = Kodiak::Transporter.new(config, options)

	dw = []
	@files.each do |file|
		dw = DirectoryWatcher.new '.', :glob => file[:source], :pre_load => true
		dw.add_observer do |*args| 
			args.each do |event| 
				if event.type == :stable then transporter.transport [file] end
			end
		end
		dw.interval = 0.25 	# polling interval
		dw.stable = 2 			# mutiple of interval for 'stable' events
		dw.start
	end		
	
	puts "Kodiak server started"
	STDIN.gets
	dw.stop			
end