Class: Autowatchr::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/autowatchr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
# File 'lib/autowatchr.rb', line 10

def initialize(options = {})
  @failing_only = @run_suite = true

  options.each_pair do |key, value|
    method = "#{key}="
    if self.respond_to?(method)
      self.send(method, value)
    end
  end
end

Instance Attribute Details

#commandObject



25
26
27
# File 'lib/autowatchr.rb', line 25

def command
  @command ||= "<%= ruby %> -I<%= include %> <% list_of_requires.each { |lib| %>-r<%= lib %> <% } %><%= predicate %>"
end

#completed_reObject



71
72
73
# File 'lib/autowatchr.rb', line 71

def completed_re
  @completed_re ||= /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/
end

#failed_results_reObject



67
68
69
# File 'lib/autowatchr.rb', line 67

def failed_results_re
  @failed_results_re ||= /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/
end

#failing_onlyObject



75
76
77
# File 'lib/autowatchr.rb', line 75

def failing_only
  @failing_only
end

#includeObject



33
34
35
# File 'lib/autowatchr.rb', line 33

def include
  @include ||= ".:#{self.lib_dir}:#{self.test_dir}"
end

#lib_dirObject



51
52
53
# File 'lib/autowatchr.rb', line 51

def lib_dir
  @lib_dir ||= "lib"
end

#lib_reObject



59
60
61
# File 'lib/autowatchr.rb', line 59

def lib_re
  @lib_re ||= '^%s.*/.*\.rb$' % self.lib_dir
end

#requireObject



37
38
39
# File 'lib/autowatchr.rb', line 37

def require
  @require
end

#rubyObject



29
30
31
# File 'lib/autowatchr.rb', line 29

def ruby
  @ruby ||= "ruby"
end

#run_methodObject



21
22
23
# File 'lib/autowatchr.rb', line 21

def run_method
  @run_method ||= :require
end

#run_suiteObject



79
80
81
# File 'lib/autowatchr.rb', line 79

def run_suite
  @run_suite
end

#test_dirObject



55
56
57
# File 'lib/autowatchr.rb', line 55

def test_dir
  @test_dir ||= "test"
end

#test_reObject



63
64
65
# File 'lib/autowatchr.rb', line 63

def test_re
  @test_re ||= '^%s.*/test_.*\.rb$' % self.test_dir
end

Instance Method Details

#eval_command(predicate) ⇒ Object



83
84
85
# File 'lib/autowatchr.rb', line 83

def eval_command(predicate)
  ERB.new(self.command).result(binding)
end

#list_of_requiresObject



41
42
43
44
45
46
47
48
49
# File 'lib/autowatchr.rb', line 41

def list_of_requires
  if @require.nil? || @require.empty?
    []
  elsif @require.is_a?(Array)
    @require
  else
    [@require]
  end
end