Module: Spork
- Defined in:
- lib/spork.rb,
lib/spork/runner.rb
Defined Under Namespace
Modules: CustomIOStreams
Classes: AppFramework, Diagnoser, Forker, Runner, Server
Class Method Summary
collapse
Class Method Details
.already_ran ⇒ Object
4
5
6
|
# File 'lib/spork.rb', line 4
def already_ran
@already_ran ||= []
end
|
.already_ran?(caller_script_and_line) ⇒ Boolean
26
27
28
29
30
|
# File 'lib/spork.rb', line 26
def already_ran?(caller_script_and_line)
return true if already_ran.include?(expanded_caller(caller_script_and_line))
already_ran << expanded_caller(caller_script_and_line)
false
end
|
.each_run(&block) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/spork.rb', line 17
def each_run(&block)
return if already_ran?(caller.first)
if @state == :using_spork
each_run_procs << block
else
yield
end
end
|
.each_run_procs ⇒ Object
8
9
10
|
# File 'lib/spork.rb', line 8
def each_run_procs
@each_run_procs ||= []
end
|
.exec_each_run(&block) ⇒ Object
45
46
47
48
49
|
# File 'lib/spork.rb', line 45
def exec_each_run(&block)
each_run_procs.each { |p| p.call }
each_run_procs.clear
yield if block_given?
end
|
.exec_prefork(&block) ⇒ Object
40
41
42
43
|
# File 'lib/spork.rb', line 40
def exec_prefork(&block)
using_spork!
yield
end
|
.expanded_caller(caller_line) ⇒ Object
51
52
53
54
55
|
# File 'lib/spork.rb', line 51
def expanded_caller(caller_line)
file, line = caller_line.split(":")
line.gsub(/:.+/, '')
File.expand_path(Dir.pwd, file) + ":" + line
end
|
.prefork(&block) ⇒ Object
12
13
14
15
|
# File 'lib/spork.rb', line 12
def prefork(&block)
return if already_ran?(caller.first)
yield
end
|
.state ⇒ Object
36
37
38
|
# File 'lib/spork.rb', line 36
def state
@state ||= :not_using_spork
end
|
.trap_class_method(klass, method_name) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/spork.rb', line 68
def trap_class_method(klass, method_name)
klass.class_eval <<-EOF, __FILE__, __LINE__ + 1
class << self
alias :#{method_name}_without_spork :#{method_name} unless method_defined?(:#{method_name}_without_spork)
def #{method_name}(*args)
Spork.each_run_procs << lambda do
#{method_name}_without_spork(*args)
end
end
end
EOF
end
|
.trap_method(klass, method_name) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/spork.rb', line 57
def trap_method(klass, method_name)
klass.class_eval <<-EOF, __FILE__, __LINE__ + 1
alias :#{method_name}_without_spork :#{method_name} unless method_defined?(:#{method_name}_without_spork)
def #{method_name}(*args)
Spork.each_run_procs << lambda do
#{method_name}_without_spork(*args)
end
end
EOF
end
|
.using_spork! ⇒ Object
32
33
34
|
# File 'lib/spork.rb', line 32
def using_spork!
@state = :using_spork
end
|