Sha256: e5b763244f64003769f474fef9f1714e479af662863b77d627743eaf59e48739

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
module Spork
  class << self
    def already_preforked
      @already_preforked ||= []
    end
    
    def already_run
      @already_run ||= []
    end
    
    def prefork(&block)
      return if already_preforked.include?(expanded_caller(caller.first))
      already_preforked << expanded_caller(caller.first)
      yield
    end
  
    def each_run(&block)
      return if @state == :preforking || (@state != :not_using_spork && already_run.include?(expanded_caller(caller.first)))
      already_run << expanded_caller(caller.first)
      yield
    end
  
    def preforking!
      @state = :preforking
    end
  
    def running!
      @state = :running
    end
  
    def state
      @state ||= :not_using_spork
    end
  
    def exec_prefork(helper_file)
      preforking!
      load(helper_file)
    end
  
    def exec_each_run(helper_file)
      running!
      load(helper_file)
    end
    
    def expanded_caller(caller_line)
      file, line = caller_line.split(":")
      line.gsub(/:.+/, '')
      File.expand_path(Dir.pwd, file) + ":" + line
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
timcharper-spork-0.4.4 lib/spork.rb
spork-0.4.4 lib/spork.rb