Class: Massimo::Watcher

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Watcher

Returns a new instance of Watcher.



10
11
12
13
14
# File 'lib/massimo/watcher.rb', line 10

def initialize(site)
  @site           = site
  @previous_files = []
  check_config
end

Class Method Details

.start(site) ⇒ Object



4
5
6
7
# File 'lib/massimo/watcher.rb', line 4

def start(site)
  Massimo::UI.say 'massimo is watching your files for changes', :growl => true
  self.new(site).run
end

Instance Method Details

#changed?Boolean

Determine if any of the Site’s files have changed.

Returns:

  • (Boolean)


43
44
45
# File 'lib/massimo/watcher.rb', line 43

def changed?
  @previous_files != check_files
end

#config_changed?Boolean

Determine if the Site’s config file has chanaged.

Returns:

  • (Boolean)


48
49
50
# File 'lib/massimo/watcher.rb', line 48

def config_changed?
  @previous_config != check_config
end

#processObject

Processes the Site if any of the files have changed.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/massimo/watcher.rb', line 29

def process
  if config_changed?
    Massimo::UI.say 'massimo is reloading your site'
    @site.reload
    @site.process
    Massimo::UI.say 'massimo has built your site', :growl => true
  elsif changed?
    Massimo::UI.say 'massimo has noticed a change'
    @site.process
    Massimo::UI.say 'massimo has built your site', :growl => true
  end
end

#runObject

Runs a loop, processing the Site whenever files have changed.



17
18
19
20
21
22
23
24
25
26
# File 'lib/massimo/watcher.rb', line 17

def run
  begin
    loop do
      Massimo::UI.report_errors { process }
      sleep 0.5
    end
  rescue Interrupt
    exit
  end
end