Class: Guard::RailsAssets

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/rails-assets.rb

Defined Under Namespace

Classes: CliRunner, RailsRunner

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ RailsAssets

Returns a new instance of RailsAssets.



6
7
8
9
10
11
# File 'lib/guard/rails-assets.rb', line 6

def initialize(watchers=[], options={})
  super
  @options = options || {}
  @run_on = @options[:run_on] || [:start, :change]
  @run_on = [@run_on] unless @run_on.respond_to?(:include?)
end

Instance Method Details

#compile_assetsObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/guard/rails-assets.rb', line 31

def compile_assets
  puts "Compiling rails assets with #{runner.class.name}."
  result = runner.compile_assets

  if result
    Notifier::notify 'Assets compiled'
    puts 'Assets compiled.'
  else
    Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed
    puts 'Failed to compile assets.'
  end
end

#reloadObject



18
19
20
21
# File 'lib/guard/rails-assets.rb', line 18

def reload
  runner.reload if runner.respond_to? :reload
  compile_assets if run_for? :reload
end

#run_allObject



23
24
25
# File 'lib/guard/rails-assets.rb', line 23

def run_all
  compile_assets if run_for? :all
end

#run_for?(command) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/guard/rails-assets.rb', line 53

def run_for? command
  @run_on.include?(command)
end

#run_on_change(paths = []) ⇒ Object



27
28
29
# File 'lib/guard/rails-assets.rb', line 27

def run_on_change(paths=[])
  compile_assets if run_for? :change
end

#runnerObject



44
45
46
47
48
49
50
51
# File 'lib/guard/rails-assets.rb', line 44

def runner
  @runner ||= begin
    runner_name = (@options[:runner] || :rails).to_s

    require "guard/rails-assets/#{runner_name}_runner"
    ::Guard::RailsAssets.const_get(runner_name.capitalize + 'Runner').new(@options)
  end
end

#startObject



13
14
15
16
# File 'lib/guard/rails-assets.rb', line 13

def start
  runner.start if runner.respond_to? :start
  compile_assets if run_for? :start
end