Class: Texas::Task::Watch

Inherits:
Base
  • Object
show all
Extended by:
OutputHelper
Defined in:
lib/texas/task/watch.rb

Class Attribute Summary collapse

Attributes inherited from Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OutputHelper

trace, verbose, warning

Methods inherited from Base

#build, #initialize

Constructor Details

This class inherits a constructor from Texas::Task::Base

Class Attribute Details

.run_optionsObject

Returns the value of attribute run_options


7
8
9
# File 'lib/texas/task/watch.rb', line 7

def run_options
  @run_options
end

Class Method Details

.default_directoriesObject

Returns the directories watched by default.


23
24
25
# File 'lib/texas/task/watch.rb', line 23

def default_directories
  [Texas.contents_subdir_name, "lib/", Texas.texas_dir]
end

.directoriesObject

Returns the directories watched, which can be extended.

Example:

Texas::Task::Watch.directories << "images/"

32
33
34
# File 'lib/texas/task/watch.rb', line 32

def directories
  @@directories ||= default_directories
end

.directories_to_watchObject


36
37
38
# File 'lib/texas/task/watch.rb', line 36

def directories_to_watch
  directories.uniq.select { |d| File.exists?(d) }
end

.rebuildObject


40
41
42
43
44
45
46
# File 'lib/texas/task/watch.rb', line 40

def rebuild
  started_at = Time.now.to_i
  Texas::Runner.new(run_options)
  finished_at = Time.now.to_i
  time = finished_at - started_at
  trace TraceInfo.new(:rebuild, "in #{time} seconds", :green)
end

Instance Method Details

#runObject


10
11
12
13
14
15
16
# File 'lib/texas/task/watch.rb', line 10

def run
  self.class.run_options = options.to_h.merge(:task => :build)
  dirs = Task::Watch.directories_to_watch
  Listen.to(*dirs) do |modified, added, removed|
    Task::Watch.rebuild
  end
end