Class: Autocuke::Runtime

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runtime

Returns a new instance of Runtime.



10
11
12
13
14
# File 'lib/autocuke/runtime.rb', line 10

def initialize(options)
  @options = options
  @root    = options.root
  @files ||= Dir[File.join(options.root, "**/*.feature")]
end

Instance Attribute Details

#current_fileObject

Returns the value of attribute current_file.



8
9
10
# File 'lib/autocuke/runtime.rb', line 8

def current_file
  @current_file
end

#filesObject

Returns the value of attribute files.



8
9
10
# File 'lib/autocuke/runtime.rb', line 8

def files
  @files
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/autocuke/runtime.rb', line 7

def options
  @options
end

#rootObject (readonly)

Returns the value of attribute root.



7
8
9
# File 'lib/autocuke/runtime.rb', line 7

def root
  @root
end

Instance Method Details

#handlerObject

Overwrite for custom handlers



60
61
62
# File 'lib/autocuke/runtime.rb', line 60

def handler
  Autocuke::Handler
end

#logObject

Logs the root and file list



37
38
39
40
41
42
43
44
45
# File 'lib/autocuke/runtime.rb', line 37

def log
  puts "Root Set To:"
  puts root
  puts         
  puts "Watching files:"
  puts "-" * 88
  puts files
  puts
end

#run!Object

Starts the EM reactor and watches each of the runtime’s files Raises an Autocuke::NoFileError if the list of files is empty



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/autocuke/runtime.rb', line 18

def run!
  raise Autocuke::NoFileError.new("No files given to watch!") if files.empty?

  log if options.verbose

  # file watching requires kqueue on OSX
  EM.kqueue = true if EM.kqueue?

  EM.run {
    watch_feature_files 
    puts "autocuke is up and running!"        
    trap "SIGINT", proc{
      puts "\nbye-bye!"
      exit          
    }
  }      
end

#stop!Object

Stops the EM reactor



65
66
67
# File 'lib/autocuke/runtime.rb', line 65

def stop!
  EM.stop
end

#watch(file) ⇒ Object

Adds a file to EM’s file watch list



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

def watch(file)
  EM.watch_file(File.expand_path(file), handler)
end

#watch_feature_filesObject

Adds each of the runtime’s files to EM’s file watch list



48
49
50
51
52
# File 'lib/autocuke/runtime.rb', line 48

def watch_feature_files
  files.each do |file|
    watch(file)
  end 
end