Class: Guard::Konacha::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/konacha/runner.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :run_all_on_start => true,
  :notification => true,
  :rails_environment_file => './config/environment'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/guard/konacha/runner.rb', line 13

def initialize(options={})
  @options = DEFAULT_OPTIONS.merge(options)

  # Require project's rails environment file to load Konacha
  # configuration
  require_rails_environment
  raise "Konacha not loaded" unless defined? ::Konacha

  # Custom formatter to handle multiple runs
  @formatter = Formatter.new
  ::Konacha.config.formatters = [@formatter]

  # Reusable session to increase performance
  @session = Capybara::Session.new(::Konacha.driver, Server.new)

  ::Konacha.mode = :runner

  UI.info "Guard::Konacha Initialized"
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



11
12
13
# File 'lib/guard/konacha/runner.rb', line 11

def formatter
  @formatter
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/guard/konacha/runner.rb', line 11

def options
  @options
end

Instance Method Details

#run(paths = ['']) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/guard/konacha/runner.rb', line 37

def run(paths = [''])
  formatter.reset

  paths.each do |path|
    if path.empty? or File.exists? real_path path
      runner.run konacha_path(path)
    end
  end

  formatter.write_summary
  notify
rescue => e
  UI.error(e)
end

#startObject



33
34
35
# File 'lib/guard/konacha/runner.rb', line 33

def start
  run if options[:run_all_on_start]
end