Class: Guard::KonachaRails::Runner

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



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

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.



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

def formatter
  @formatter
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

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



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

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



31
32
33
# File 'lib/guard/konacha/rails/runner.rb', line 31

def start
  run if options[:run_all_on_start]
end