local_pac 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/Gemfile +2 -0
  2. data/bin/local_pac +47 -2
  3. data/features/initializer.feature +23 -0
  4. data/features/show_config.feature +22 -0
  5. data/features/support/env.rb +1 -1
  6. data/files/config.yaml +6 -0
  7. data/files/git-hook.erb +24 -0
  8. data/lib/local_pac/actions/create_directory.rb +33 -0
  9. data/lib/local_pac/actions/create_file.rb +48 -0
  10. data/lib/local_pac/actions/create_repository.rb +38 -0
  11. data/lib/local_pac/config.rb +64 -0
  12. data/lib/local_pac/data.rb +23 -0
  13. data/lib/local_pac/erb_generator.rb +34 -0
  14. data/lib/local_pac/exceptions.rb +9 -0
  15. data/lib/local_pac/file_server.rb +10 -3
  16. data/lib/local_pac/fileable.rb +12 -0
  17. data/lib/local_pac/git.rb +63 -0
  18. data/lib/local_pac/git_file.rb +18 -0
  19. data/lib/local_pac/git_repository.rb +52 -0
  20. data/lib/local_pac/initializer.rb +28 -0
  21. data/lib/local_pac/local_storage.rb +21 -0
  22. data/lib/local_pac/logger.rb +0 -5
  23. data/lib/local_pac/main.rb +24 -0
  24. data/lib/local_pac/pac_file.rb +5 -5
  25. data/lib/local_pac/runner.rb +29 -0
  26. data/lib/local_pac/spec_helper_file_server.rb +41 -0
  27. data/lib/local_pac/template_file.rb +19 -0
  28. data/lib/local_pac/template_repository.rb +22 -0
  29. data/lib/local_pac/ui_logger.rb +12 -0
  30. data/lib/local_pac/version.rb +1 -1
  31. data/lib/local_pac.rb +30 -4
  32. data/local_pac.gemspec +1 -0
  33. data/share/examples/config.yaml +5 -0
  34. data/spec/actions/create_directory_spec.rb +47 -0
  35. data/spec/actions/create_file_spec.rb +95 -0
  36. data/spec/actions/create_repository_spec.rb +47 -0
  37. data/spec/config_spec.rb +113 -0
  38. data/spec/data_spec.rb +34 -0
  39. data/spec/erb_generator_spec.rb +31 -0
  40. data/spec/features/fetch_proxy_pac_spec.rb +30 -12
  41. data/spec/git_repository_spec.rb +60 -0
  42. data/spec/git_spec.rb +100 -0
  43. data/spec/initializer_spec.rb +29 -0
  44. data/spec/local_storage_spec.rb +59 -0
  45. data/spec/pac_file_spec.rb +14 -14
  46. data/spec/runner_spec.rb +42 -0
  47. data/spec/support/git.rb +52 -0
  48. data/spec/support/reporting.rb +1 -0
  49. data/spec/support/rspec.rb +3 -0
  50. data/spec/template_file_spec.rb +25 -0
  51. data/spec/template_repository_spec.rb +44 -0
  52. metadata +74 -5
  53. data/lib/local_pac/pac_manager.rb +0 -55
  54. data/spec/pac_manager_spec.rb +0 -52
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe GitRepository do
5
+ let(:git_repo) { 'git_repo' }
6
+ let(:compressor) do
7
+ Class.new do
8
+ def prepare(file)
9
+ end
10
+ end
11
+ end
12
+
13
+ let(:creator) do
14
+ Class.new do
15
+ attr_reader :file
16
+ attr_accessor :compressed_content
17
+ def initialize(file)
18
+ @file = file
19
+ end
20
+
21
+ def name
22
+ file.name
23
+ end
24
+
25
+ def content
26
+ file.content
27
+ end
28
+ end
29
+ end
30
+
31
+ context '#files' do
32
+ it 'returns a list of files matching pattern' do
33
+ git_init(git_repo)
34
+ create_file(File.join(git_repo, 'file1.txt'))
35
+ git_add(git_repo, 'file1.txt')
36
+
37
+ file2 = create_file(File.join(git_repo, 'file2.pac'), 'data file2.pac')
38
+ git_add(git_repo, 'file2.pac')
39
+
40
+ git_commit(git_repo)
41
+
42
+ repo = GitRepository.new(File.join(working_directory, git_repo, '.git'), compressor, creator)
43
+ expect(repo[:file2].content).to eq(File.read(file2))
44
+ end
45
+
46
+ it 'supports directories as well' do
47
+ git_init(git_repo)
48
+ create_file(File.join(git_repo, 'file1.txt'))
49
+ git_add(git_repo, 'file1.txt')
50
+
51
+ file2 = create_file(File.join(git_repo, 'dir', 'file2.pac'), 'data file2.pac')
52
+ git_add(git_repo, 'dir/file2.pac')
53
+
54
+ git_commit(git_repo)
55
+
56
+ repo = GitRepository.new(File.join(working_directory, git_repo, '.git'), compressor, creator)
57
+ expect(repo['dir::file2'.to_sym].content).to eq(File.read(file2))
58
+ end
59
+ end
60
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Git do
5
+ let(:git_repo) { 'git_repo' }
6
+
7
+ context '#init' do
8
+ it 'creates a new repository' do
9
+ switch_to_working_directory do
10
+ Git.init(git_repo)
11
+ end
12
+
13
+ expect(path_exists?(git_repo)).to be_true
14
+ end
15
+ end
16
+
17
+ context '#ls_tree' do
18
+ it 'list files in repo' do
19
+ git_init(git_repo)
20
+ create_file(File.join(git_repo, 'file.txt'))
21
+ git_add(git_repo, 'file.txt')
22
+ git_commit(git_repo)
23
+
24
+ Dir.chdir(::File.join(working_directory, git_repo)) do
25
+ expect(Git.ls_tree.first).to include('file.txt')
26
+ end
27
+ end
28
+ end
29
+
30
+ context '#ls_files' do
31
+ it 'list files in repo' do
32
+ git_init(git_repo)
33
+ create_file(File.join(git_repo, 'file.txt'))
34
+ git_add(git_repo, 'file.txt')
35
+ git_commit(git_repo)
36
+
37
+ Dir.chdir(::File.join(working_directory, git_repo)) do
38
+ expect(Git.ls_files).to include('file.txt')
39
+ end
40
+ end
41
+
42
+ it 'list files in repo and filter' do
43
+ git_init(git_repo)
44
+ create_file(File.join(git_repo, 'file1.txt'))
45
+ git_add(git_repo, 'file1.txt')
46
+
47
+ create_file(File.join(git_repo, 'file2.txt'))
48
+ git_add(git_repo, 'file2.txt')
49
+
50
+ git_commit(git_repo)
51
+
52
+ Dir.chdir(::File.join(working_directory, git_repo)) do
53
+ expect(Git.ls_files('file1.txt')).to eq(['file1.txt'])
54
+ end
55
+ end
56
+ end
57
+
58
+ context '#add' do
59
+ it 'add dir/file to repository' do
60
+ git_init(git_repo)
61
+ create_file(File.join(git_repo, 'file.txt'))
62
+
63
+ Dir.chdir(::File.join(working_directory, git_repo)) do
64
+ Git.add('file.txt')
65
+ end
66
+
67
+ expect(git_status(git_repo)).to include("\tnew file: file.txt")
68
+ end
69
+ end
70
+
71
+ context '#commit' do
72
+ it 'commit dir/file to repository' do
73
+
74
+ git_init(git_repo)
75
+
76
+ create_file(File.join(git_repo, 'file.txt'))
77
+
78
+ git_add(git_repo, 'file.txt')
79
+
80
+ Dir.chdir(::File.join(working_directory, git_repo)) do
81
+ Git.commit('file.txt')
82
+ end
83
+
84
+ expect(git_status(git_repo)).to include('nothing to commit, working directory clean')
85
+ end
86
+ end
87
+
88
+ context '#show' do
89
+ it 'show ref/sha in repository' do
90
+ git_init(git_repo)
91
+ create_file(File.join(git_repo, 'file.txt'))
92
+ git_add(git_repo, 'file.txt')
93
+ git_commit(git_repo)
94
+
95
+ Dir.chdir(::File.join(working_directory, git_repo)) do
96
+ expect(Git.show.first).to include('commit')
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Initializer do
5
+
6
+ context '#run' do
7
+ it 'creates all files/directories neccessary to run local_pac' do
8
+ config_string = <<-EOS.strip_heredoc
9
+ :log_sink: #{File.join(working_directory, 'log')}
10
+ :local_storage: #{File.join(working_directory, 'storage', 'cache.git')}
11
+ :executable: #{File.join(working_directory, 'bin', 'local_pac')}
12
+ :pid_file: #{File.join(working_directory, 'run', 'pid')}
13
+ :gem_path: []
14
+ EOS
15
+ config_file = create_file('config.yaml', config_string)
16
+
17
+ config = LocalPac::Config.new({}, config_file)
18
+ initializer = Initializer.new(config)
19
+ silence(:stderr) do
20
+ initializer.run
21
+ end
22
+
23
+ expect(path_exists?('log')).to be_true
24
+ expect(path_exists?('storage/cache.git')).to be_true
25
+ expect(path_exists?(File.join('storage', 'cache.git', 'hooks', 'pre-receive'))).to be_true
26
+ expect(path_exists?('run')).to be_true
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe LocalStorage do
5
+ let(:valid_pac_file) do <<-EOS.strip_heredoc
6
+ function FindProxyForURL(url, host) {
7
+ return "DIRECT"
8
+ }
9
+ EOS
10
+ end
11
+
12
+ context '#initialize' do
13
+ it 'initializes storage' do
14
+ file = double('File')
15
+ allow(file).to receive(:name).and_return(:file1)
16
+
17
+ repo = double('GitRepository')
18
+ expect(repo).to receive(:[]).and_return(file)
19
+
20
+ storage = LocalStorage.new(repo)
21
+ file = storage.find('file1')
22
+ expect(file.name).to eq(:file1)
23
+ end
24
+
25
+ context '#find' do
26
+ it 'returns file if exists' do
27
+ file = double('GitFile')
28
+ allow(file).to receive(:name).and_return(:file1)
29
+
30
+ repo = double('GitRepository')
31
+ expect(repo).to receive(:[]).and_return(file)
32
+
33
+ storage = LocalStorage.new(repo)
34
+ file = storage.find('file1')
35
+ expect(file.name).to eq(:file1)
36
+ end
37
+
38
+ it 'returns file for pac in subdir' do
39
+ file = double('GitFile')
40
+ allow(file).to receive(:name).and_return(:'dir::file1')
41
+
42
+ repo = double('GitRepository')
43
+ expect(repo).to receive(:[]).and_return(file)
44
+
45
+ storage = LocalStorage.new(repo)
46
+ file = storage.find('dir/file1')
47
+ expect(file.name).to eq(:'dir::file1')
48
+ end
49
+
50
+ it 'returns null file if does not exist' do
51
+ repo = double('GitRepository')
52
+ expect(repo).to receive(:[]).and_return(nil)
53
+
54
+ storage = LocalStorage.new(repo)
55
+ expect(storage.find('unexist')).to be_nil
56
+ end
57
+ end
58
+ end
59
+ end
@@ -2,31 +2,30 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe PacFile do
5
- context '#path' do
6
- it 'has a path' do
7
- file = PacFile.new('/usr/share/file1.pac')
8
- expect(file.path).to eq('/usr/share/file1.pac')
9
- end
10
- end
11
-
12
5
  context '#name' do
13
6
  it 'has a name' do
14
- file = PacFile.new('/usr/share/file1.pac')
7
+ git_file = double('GitFile')
8
+ allow(git_file).to receive(:name).and_return(:file1)
9
+
10
+ file = PacFile.new(git_file)
15
11
  expect(file.name).to eq(:file1)
16
12
  end
17
13
  end
18
14
 
19
15
  context '#content' do
20
16
  it 'returns the content of file' do
21
- file = create_file('file1.pac', 'content')
22
- file = PacFile.new(file)
23
- expect(file.content).to eq('content')
17
+ git_file = double('GitFile')
18
+ allow(git_file).to receive(:content).and_return('asdf')
19
+
20
+ file = PacFile.new(git_file)
21
+ expect(file.content).to eq('asdf')
24
22
  end
25
23
  end
26
24
 
27
25
  context '#nil?' do
28
26
  it 'is always false' do
29
- file = PacFile.new('/usr/share/file1.pac')
27
+ git_file = double('GitFile')
28
+ file = PacFile.new(git_file)
30
29
  expect(file.nil?).to be_false
31
30
  end
32
31
  end
@@ -36,8 +35,9 @@ describe PacFile do
36
35
  handler = double('handler')
37
36
  expect(handler).to receive(:prepare)
38
37
 
39
- file = create_file('file1.pac', 'content')
40
- file = PacFile.new(file)
38
+ git_file = double('GitFile')
39
+ allow(git_file).to receive(:content).and_return('asdf')
40
+ file = PacFile.new(git_file)
41
41
  file.prepare(handler)
42
42
  end
43
43
  end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Runner do
5
+ context '#initialize' do
6
+ it 'expects a command string' do
7
+ Runner.new('echo')
8
+ end
9
+
10
+ end
11
+
12
+ context '#run' do
13
+ it 'runs a command' do
14
+ runner = Runner.new('echo')
15
+ expect {
16
+ runner.run
17
+ }.not_to raise_error
18
+ end
19
+
20
+ it 'fails on error file not found' do
21
+ runner = Runner.new('asdfasdf asfd')
22
+ expect {
23
+ runner.run
24
+ }.to raise_error RuntimeError
25
+ end
26
+
27
+ it 'fails on error status code' do
28
+ runner = Runner.new('exit 1')
29
+ expect {
30
+ runner.run
31
+ }.to raise_error RuntimeError
32
+ end
33
+ end
34
+
35
+ context '#result' do
36
+ it 'returns stdout as array' do
37
+ runner = Runner.new("echo -E \"hello\nworld\"")
38
+
39
+ expect(runner.result).to eq(["hello", "world"])
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,52 @@
1
+ require 'fedux_org/stdlib/filesystem'
2
+
3
+ module LocalPac
4
+ module SpecHelper
5
+ module GitHelper
6
+ include FeduxOrg::Stdlib::Filesystem
7
+
8
+ def root_directory
9
+ ::File.expand_path('../../../', __FILE__)
10
+ end
11
+
12
+ def git_init(path)
13
+ switch_to_working_directory do
14
+ Git.init(path)
15
+ end
16
+
17
+ File.join(working_directory, path)
18
+ end
19
+
20
+ def git_add(repo, object)
21
+ Dir.chdir(::File.join(working_directory, repo)) do
22
+ Git.add(object)
23
+ end
24
+
25
+ File.join(working_directory, repo, object)
26
+ end
27
+
28
+ def git_status(repo)
29
+ Dir.chdir(::File.join(working_directory, repo)) do
30
+ Git.status
31
+ end
32
+ end
33
+
34
+ def git_commit(repo, message = 'Yay... Added objects')
35
+ Dir.chdir(::File.join(working_directory, repo)) do
36
+ Git.commit(message)
37
+ end
38
+ end
39
+
40
+ def git_show(repo, sha)
41
+ Dir.chdir(::File.join(working_directory, repo)) do
42
+ Git.show(sha)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # encoding: utf-8
50
+ RSpec.configure do |c|
51
+ c.include LocalPac::SpecHelper::GitHelper
52
+ end
@@ -0,0 +1 @@
1
+ require 'active_support/core_ext/kernel/reporting'
@@ -2,4 +2,7 @@ RSpec.configure do |c|
2
2
  c.filter_run_including :focus => true
3
3
  c.run_all_when_everything_filtered = true
4
4
  c.treat_symbols_as_metadata_keys_with_true_values = true
5
+ c.before(:each) {
6
+ LocalPac.ui_logger.level = ::Logger::UNKNOWN
7
+ }
5
8
  end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe TemplateFile do
5
+ context '#initialize' do
6
+ it 'requires a path' do
7
+ TemplateFile.new('/path/asfd')
8
+ end
9
+ end
10
+
11
+ context '#name' do
12
+ it 'has a name based on path' do
13
+ file = TemplateFile.new('/path/asdf')
14
+ expect(file.name).to eq(:asdf)
15
+ end
16
+ end
17
+
18
+ context '#read' do
19
+ it 'reads content' do
20
+ file = create_file('asdf', 'content')
21
+ file = TemplateFile.new(file)
22
+ expect(file.read).to eq('content')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe TemplateRepository do
5
+ let(:creator_klass) do
6
+ Class.new do
7
+ def initialize(path)
8
+ end
9
+
10
+ def name
11
+ :template
12
+ end
13
+
14
+ def content
15
+ 'content'
16
+ end
17
+ end
18
+ end
19
+
20
+ context '#initialize' do
21
+ it 'accepts a path' do
22
+ TemplateRepository.new('path', creator_klass)
23
+ end
24
+ end
25
+
26
+ context '#find' do
27
+
28
+ it 'finds a template by name' do
29
+ dir = create_directory('repo')
30
+ file = create_file('repo/template.erb')
31
+ repo = TemplateRepository.new(dir, creator_klass)
32
+ template_file = repo.find(File.basename(file, '.*'))
33
+ expect(template_file.name).to eq(:template)
34
+ end
35
+
36
+ it 'finds a template by name' do
37
+ dir = create_directory('repo')
38
+ file = create_file('repo/template.erb')
39
+ repo = TemplateRepository.new(dir, creator_klass)
40
+ template_file = repo.find(File.basename(file, '.*').to_sym)
41
+ expect(template_file.name).to eq(:template)
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_pac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-11 00:00:00.000000000 Z
12
+ date: 2014-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: git_hook-pre_receive
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.2
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.0.2
110
126
  description: ! 'This gem helps you to serve proxy.pacs locallly
111
127
 
112
128
  '
@@ -126,36 +142,73 @@ files:
126
142
  - bin/local_pac
127
143
  - config.ru
128
144
  - features/fetch_proxy_pac.feature
145
+ - features/initializer.feature
146
+ - features/show_config.feature
129
147
  - features/support/env.rb
148
+ - files/config.yaml
149
+ - files/git-hook.erb
130
150
  - files/proxy.pac
131
151
  - lib/local_pac.rb
152
+ - lib/local_pac/actions/create_directory.rb
153
+ - lib/local_pac/actions/create_file.rb
154
+ - lib/local_pac/actions/create_repository.rb
155
+ - lib/local_pac/config.rb
156
+ - lib/local_pac/data.rb
157
+ - lib/local_pac/erb_generator.rb
158
+ - lib/local_pac/exceptions.rb
132
159
  - lib/local_pac/file_server.rb
160
+ - lib/local_pac/fileable.rb
161
+ - lib/local_pac/git.rb
162
+ - lib/local_pac/git_file.rb
163
+ - lib/local_pac/git_repository.rb
164
+ - lib/local_pac/initializer.rb
133
165
  - lib/local_pac/java_script_compressor.rb
166
+ - lib/local_pac/local_storage.rb
134
167
  - lib/local_pac/logger.rb
168
+ - lib/local_pac/main.rb
135
169
  - lib/local_pac/null_pac_file.rb
136
170
  - lib/local_pac/pac_file.rb
137
171
  - lib/local_pac/pac_file_validator.rb
138
- - lib/local_pac/pac_manager.rb
172
+ - lib/local_pac/runner.rb
139
173
  - lib/local_pac/spec_helper.rb
174
+ - lib/local_pac/spec_helper_file_server.rb
175
+ - lib/local_pac/template_file.rb
176
+ - lib/local_pac/template_repository.rb
177
+ - lib/local_pac/ui_logger.rb
140
178
  - lib/local_pac/version.rb
141
179
  - local_pac.gemspec
142
180
  - share/archlinux/PKGBUILD
143
181
  - share/archlinux/startup.erb
182
+ - share/examples/config.yaml
144
183
  - share/systemd/local_pac.service
145
184
  - share/systemd/local_pac.socket
146
185
  - share/systemd/local_pac@.service
186
+ - spec/actions/create_directory_spec.rb
187
+ - spec/actions/create_file_spec.rb
188
+ - spec/actions/create_repository_spec.rb
189
+ - spec/config_spec.rb
190
+ - spec/data_spec.rb
191
+ - spec/erb_generator_spec.rb
147
192
  - spec/features/fetch_proxy_pac_spec.rb
193
+ - spec/git_repository_spec.rb
194
+ - spec/git_spec.rb
195
+ - spec/initializer_spec.rb
148
196
  - spec/java_script_compressor_spec.rb
197
+ - spec/local_storage_spec.rb
149
198
  - spec/null_pac_file_spec.rb
150
199
  - spec/pac_file_spec.rb
151
200
  - spec/pac_file_validator_spec.rb
152
- - spec/pac_manager_spec.rb
201
+ - spec/runner_spec.rb
153
202
  - spec/spec_helper.rb
154
203
  - spec/support/environment.rb
155
204
  - spec/support/filesystem.rb
205
+ - spec/support/git.rb
156
206
  - spec/support/rack_test.rb
207
+ - spec/support/reporting.rb
157
208
  - spec/support/rspec.rb
158
209
  - spec/support/string.rb
210
+ - spec/template_file_spec.rb
211
+ - spec/template_repository_spec.rb
159
212
  homepage: https://github.com/dg-vrnetze/local_pac
160
213
  licenses:
161
214
  - MIT
@@ -183,17 +236,33 @@ specification_version: 3
183
236
  summary: Serve local proxy pac
184
237
  test_files:
185
238
  - features/fetch_proxy_pac.feature
239
+ - features/initializer.feature
240
+ - features/show_config.feature
186
241
  - features/support/env.rb
242
+ - spec/actions/create_directory_spec.rb
243
+ - spec/actions/create_file_spec.rb
244
+ - spec/actions/create_repository_spec.rb
245
+ - spec/config_spec.rb
246
+ - spec/data_spec.rb
247
+ - spec/erb_generator_spec.rb
187
248
  - spec/features/fetch_proxy_pac_spec.rb
249
+ - spec/git_repository_spec.rb
250
+ - spec/git_spec.rb
251
+ - spec/initializer_spec.rb
188
252
  - spec/java_script_compressor_spec.rb
253
+ - spec/local_storage_spec.rb
189
254
  - spec/null_pac_file_spec.rb
190
255
  - spec/pac_file_spec.rb
191
256
  - spec/pac_file_validator_spec.rb
192
- - spec/pac_manager_spec.rb
257
+ - spec/runner_spec.rb
193
258
  - spec/spec_helper.rb
194
259
  - spec/support/environment.rb
195
260
  - spec/support/filesystem.rb
261
+ - spec/support/git.rb
196
262
  - spec/support/rack_test.rb
263
+ - spec/support/reporting.rb
197
264
  - spec/support/rspec.rb
198
265
  - spec/support/string.rb
266
+ - spec/template_file_spec.rb
267
+ - spec/template_repository_spec.rb
199
268
  has_rdoc:
@@ -1,55 +0,0 @@
1
- module LocalPac
2
- class PacManager
3
-
4
- private
5
-
6
- attr_reader :cache, :null_file, :paths, :creator, :content_handler, :validator
7
-
8
- public
9
-
10
- def initialize(paths = default_paths, creator = PacFile)
11
- @paths = Array(paths)
12
- @creator = creator
13
- @cache = ActiveSupport::Cache::MemoryStore.new
14
- @null_file = proc { NullPacFile.new }
15
- @content_handler = JavaScriptCompressor.new
16
- @validator = PacFileValidator.new
17
- end
18
-
19
- def find(name)
20
- name = File.basename(name, '.pac').to_sym
21
-
22
- cache.fetch(name) do
23
- file = valid_pac_files.find(null_file) { |f| f.name == name }
24
- file.prepare(content_handler)
25
-
26
- file
27
- end
28
- end
29
-
30
- private
31
-
32
- def pac_files
33
- paths.reduce([]) do |memo, path|
34
- memo.concat Dir.glob(File.join(path, '*.pac')).collect { |f| creator.new(f) }
35
- end
36
- end
37
-
38
- def valid_pac_files
39
- files = []
40
- pac_files.each do |f|
41
- files << f if validator.valid?(f)
42
- end
43
-
44
- files
45
- end
46
-
47
- def default_paths
48
- [
49
- File.expand_path(File.join(ENV['HOME'], '.config', 'pacfiles')),
50
- File.expand_path(File.join(ENV['HOME'], '.pacfiles')),
51
- File.expand_path('../../../files', __FILE__),
52
- ]
53
- end
54
- end
55
- end