Class: Guard::Post

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/post.rb

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}, &block) ⇒ Post

Returns a new instance of Post.



7
8
9
10
11
12
13
# File 'lib/guard/post.rb', line 7

def initialize(watchers = [], options = {}, &block)
  super
  @options = {
    :all_on_start => true,
    :rails        => false
  }.update(options)
end

Instance Method Details

#ignored?(path) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/guard/post.rb', line 54

def ignored?(path)
  File.basename(path)[0] == "_"
end

#run_allObject



24
25
26
# File 'lib/guard/post.rb', line 24

def run_all
  run_on_change(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
end

#run_on_change(paths) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/guard/post.rb', line 28

def run_on_change(paths)
  trap("SIGINT") { exit! }
  changed_files = paths.reject { |f| ignored?(f) }.map do |file|
    begin
      expanded    = ::File.expand_path(file)
      ::Guard::UI.info "-> updating '#{file}'...", :reset => true
      update_file(file)
      ::Guard::UI.info "-> updated '#{file}'", :reset => true
      file
    rescue Exception => e
      puts e.backtrace.join("\n")
      puts e.inspect
    end
    file
  end.compact
end

#startObject



15
16
17
18
19
20
21
22
# File 'lib/guard/post.rb', line 15

def start
  if @options[:rails] == true
    ::Guard::UI.info "-> Loading Rails...", :reset => true
    require File.expand_path("../config/environment", __FILE__)
    ::Guard::UI.info "-> Loaded Rails '#{Rails.env.to_s}' environment", :reset => true
  end
  true
end

#update_file(file) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/guard/post.rb', line 45

def update_file(file)
  case @options[:update]
  when ::Symbol
    Object.send(@options[:update], file)
  else
    @options[:update].call(file)
  end
end