forked from jasmine/jasmine-gem
/
configuration.rb
83 lines (68 loc) · 1.79 KB
/
configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module Jasmine
class Configuration
attr_writer :jasmine_css_files, :css_files
attr_writer :jasmine_files, :boot_files, :src_files
attr_accessor :jasmine_path, :spec_path, :boot_path, :src_path, :spec_files
attr_accessor :jasmine_dir, :spec_dir, :boot_dir, :src_dir
#TODO: these are largely client concerns, move them.
attr_accessor :port, :browser, :host, :result_batch_size
def initialize()
@rack_paths = {}
@apps = []
@path_mappers = []
@jasmine_css_files = lambda { [] }
@css_files = lambda { [] }
@jasmine_files = lambda { [] }
@boot_files = lambda { [] }
@src_files = lambda { [] }
@spec_files = lambda { [] }
end
def css_files
map(@jasmine_css_files, :jasmine) +
map(@css_files, :src)
end
def js_files
map(@jasmine_files, :jasmine) +
map(@src_files, :src) +
map(@spec_files, :spec) +
map(@boot_files, :boot)
end
def rack_path_map
{}.merge(@rack_paths)
end
def add_rack_path(path, rack_app_lambda)
@rack_paths[path] = rack_app_lambda
end
def rack_apps
[] + @apps
end
def add_rack_app(app, &block)
@apps << [app, block]
end
def add_path_mapper(mapper)
@path_mappers << mapper.call(self)
end
def port
@port ||= Jasmine.find_unused_port
end
def browser
@browser || 'firefox'
end
def host
@host || 'http://localhost'
end
def result_batch_size
@result_batch_size || 50
end
private
def map(paths, type)
@path_mappers.inject(paths.call) do |paths, mapper|
if mapper.respond_to?("map_#{type}_paths")
mapper.send("map_#{type}_paths", paths)
else
paths
end
end
end
end
end