Sha256: cd742d7b8f88cdf915defcf82c38e76892b3c2c1ec0ded0390380c5bef4a4a2d

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require "eventmachine"
require "autocuke/handler"

module Autocuke
  class Runtime
    
    attr_reader   :root,  :options
    attr_accessor :files, :current_file
    
    def initialize(options)
      @options = options
      @root    = options.root
      @files ||= Dir[File.join(options.root, "**/*.feature")]
    end

    # Starts the EM reactor and watches each of the runtime's files
    # Raises an Autocuke::NoFileError if the list of files is empty
    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
    
    # Logs the root and file list
    def log
      puts "Root Set To:"
      puts root
      puts         
      puts "Watching files:"
      puts "-" * 88
      puts files
      puts
    end
    
    # Adds each of the runtime's files to EM's file watch list
    def watch_feature_files
      files.each do |file|
        watch(file)
      end 
    end
    
    # Adds a file to EM's file watch list
    def watch(file)
      EM.watch_file(File.expand_path(file), handler)
    end
    
    # Overwrite for custom handlers
    def handler
      Autocuke::Handler
    end
    
    # Stops the EM reactor
    def stop!
      EM.stop
    end
     
  end # Runtime
end # Autocuke

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
autocuke-0.1.1 lib/autocuke/runtime.rb