class Guard::RailsAssets

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/rails-assets.rb, line 5
def initialize(options = {})
  super
  @options = options || {}
  @run_on = @options[:run_on] || [:start, :change]
  @run_on = [@run_on] unless @run_on.respond_to?(:include?)
end
template(plugin_location) click to toggle source
# File lib/guard/rails-assets.rb, line 56
def self.template(plugin_location)
  File.read(template_path(plugin_location))
end
template_path(plugin_location) click to toggle source
# File lib/guard/rails-assets.rb, line 60
def self.template_path(plugin_location)
  # workaround because Guard discards the '-' when detecting template path
  File.join(plugin_location, 'lib', 'guard', 'rails-assets', 'templates', 'Guardfile')
end

Public Instance Methods

compile_assets() click to toggle source
# File lib/guard/rails-assets.rb, line 30
def compile_assets
  puts "Compiling rails assets with #{runner.class.name}."
  result = runner.compile_assets

  if result
    Compat::UI.notify 'Assets compiled'
    puts 'Assets compiled.'
  else
    Compat::UI.notify 'see the details in the terminal', title: "Can't compile assets", image: :failed
    puts 'Failed to compile assets.'
  end
end
reload() click to toggle source
# File lib/guard/rails-assets.rb, line 17
def reload
  runner.reload if runner.respond_to? :reload
  compile_assets if run_for? :reload
end
run_all() click to toggle source
# File lib/guard/rails-assets.rb, line 22
def run_all
  compile_assets if run_for? :all
end
run_for?(command) click to toggle source
# File lib/guard/rails-assets.rb, line 52
def run_for?(command)
  @run_on.include?(command)
end
run_on_change(_paths = []) click to toggle source
# File lib/guard/rails-assets.rb, line 26
def run_on_change(_paths = [])
  compile_assets if run_for? :change
end
runner() click to toggle source
# File lib/guard/rails-assets.rb, line 43
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
start() click to toggle source
# File lib/guard/rails-assets.rb, line 12
def start
  runner.start if runner.respond_to? :start
  compile_assets if run_for? :start
end