local_pac 0.1.13 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/{LICENSE.txt → LICENSE.md} +0 -0
  2. data/README.DEVELOPER.md +7 -0
  3. data/README.md +138 -2
  4. data/Rakefile +16 -8
  5. data/app/controllers/application_controller.rb +5 -3
  6. data/app/controllers/assets_controller.rb +3 -2
  7. data/app/controllers/file_serve_controller.rb +3 -6
  8. data/app/controllers/lookup_controller.rb +9 -9
  9. data/app/locales/en.yml +1 -0
  10. data/app/views/application.haml +1 -1
  11. data/bin/local_pac +49 -64
  12. data/config.ru +24 -7
  13. data/features/initializer.feature +4 -4
  14. data/features/show_status.feature +2 -2
  15. data/files/config.yaml +2 -2
  16. data/files/example-config.erb +10 -12
  17. data/files/git-hook.erb +1 -0
  18. data/lib/local_pac.rb +22 -5
  19. data/lib/local_pac/actions/create_directory.rb +2 -2
  20. data/lib/local_pac/actions/create_file.rb +8 -2
  21. data/lib/local_pac/actions/create_repository.rb +6 -8
  22. data/lib/local_pac/actions/get_system_information.rb +78 -0
  23. data/lib/local_pac/actions/print_newline.rb +19 -0
  24. data/lib/local_pac/actions/print_title.rb +41 -0
  25. data/lib/local_pac/actions/reload_configuration.rb +21 -0
  26. data/lib/local_pac/actions/reload_local_storage.rb +22 -0
  27. data/lib/local_pac/actions/send_signal.rb +32 -0
  28. data/lib/local_pac/actions/show_config.rb +10 -0
  29. data/lib/local_pac/actions/show_process_information.rb +94 -0
  30. data/lib/local_pac/application_status.rb +34 -0
  31. data/lib/local_pac/cli/helper.rb +34 -0
  32. data/lib/local_pac/cli/reload.rb +36 -0
  33. data/lib/local_pac/config.rb +15 -13
  34. data/lib/local_pac/exceptions.rb +6 -0
  35. data/lib/local_pac/file.rb +32 -0
  36. data/lib/local_pac/git.rb +20 -6
  37. data/lib/local_pac/git_repository.rb +40 -28
  38. data/lib/local_pac/git_storage.rb +60 -0
  39. data/lib/local_pac/initializer.rb +8 -5
  40. data/lib/local_pac/local_storage.rb +3 -4
  41. data/lib/local_pac/main.rb +2 -2
  42. data/lib/local_pac/{null_pac_file.rb → null_file.rb} +5 -1
  43. data/lib/local_pac/server.rb +1 -1
  44. data/lib/local_pac/spec_helper_file_server.rb +6 -5
  45. data/lib/local_pac/template_file.rb +1 -1
  46. data/lib/local_pac/template_repository.rb +3 -3
  47. data/lib/local_pac/version.rb +1 -1
  48. data/local_pac.gemspec +13 -9
  49. data/script/console +1 -1
  50. data/share/archlinux/PKGBUILD +4 -1
  51. data/share/archlinux/config.yaml +1 -1
  52. data/spec/actions/create_directory_spec.rb +3 -3
  53. data/spec/actions/create_file_spec.rb +23 -2
  54. data/spec/actions/create_repository_spec.rb +3 -3
  55. data/spec/actions/get_system_information_spec.rb +22 -0
  56. data/spec/actions/print_new_line_spec.rb +36 -0
  57. data/spec/actions/print_title_spec.rb +50 -0
  58. data/spec/actions/reload_configuration_spec.rb +38 -0
  59. data/spec/actions/reload_repository_spec.rb +35 -0
  60. data/spec/actions/send_signal_spec.rb +58 -0
  61. data/spec/actions/show_config_spec.rb +22 -0
  62. data/spec/actions/show_process_information_spec.rb +45 -0
  63. data/spec/application_status_spec.rb +40 -0
  64. data/spec/config_spec.rb +11 -11
  65. data/spec/features/fetch_proxy_pac_spec.rb +11 -10
  66. data/spec/features/lookup_proxy_spec.rb +32 -40
  67. data/spec/file_spec.rb +56 -0
  68. data/spec/git_spec.rb +13 -7
  69. data/spec/git_storage_spec.rb +64 -0
  70. data/spec/initializer_spec.rb +7 -5
  71. data/spec/{null_pac_file_spec.rb → null_file_spec.rb} +6 -6
  72. data/spec/proxy_pac/pac_result_html_stylist_spec.rb +3 -2
  73. data/spec/runner_spec.rb +1 -1
  74. data/spec/spec_helper.rb +2 -2
  75. data/spec/spec_helper_features.rb +2 -2
  76. data/spec/support/config.rb +5 -0
  77. data/spec/support/filesystem.rb +1 -1
  78. data/spec/support/git.rb +23 -2
  79. data/spec/support/helper_features.rb +23 -0
  80. data/spec/template_repository_spec.rb +2 -2
  81. metadata +113 -32
  82. data/lib/local_pac/git_file.rb +0 -18
  83. data/lib/local_pac/pac_file.rb +0 -27
  84. data/spec/git_repository_spec.rb +0 -60
  85. data/spec/pac_file_spec.rb +0 -44
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ class GitStorage
4
+ private
5
+
6
+ attr_reader :storage_path, :data, :repository, :file_creator, :null_file
7
+
8
+ public
9
+
10
+ def initialize(storage_path, compressor_engine = JavaScriptCompressor, file_creator = LocalPac::File, null_file = LocalPac::NullFile.new)
11
+ @storage_path = ::File.expand_path(storage_path)
12
+ @file_creator = file_creator
13
+ @null_file = null_file
14
+
15
+ begin
16
+ @repository = Rugged::Repository.new(storage_path)
17
+ rescue Rugged::RepositoryError
18
+ GitRepository.create(storage_path)
19
+ @repository = Rugged::Repository.new(storage_path)
20
+ end
21
+
22
+ mutex = Mutex.new
23
+ mutex.synchronize do
24
+ @data = pac_files.reduce({}) do |memo, file|
25
+ compressor_engine.new.prepare(file)
26
+ memo[file.name.to_sym] = file
27
+
28
+ memo
29
+ end
30
+ end
31
+ end
32
+
33
+ def [](key)
34
+ data.fetch(key, null_file)
35
+ end
36
+
37
+ private
38
+
39
+ def pac_files
40
+ LocalPac.ui_logger.debug "I'm using the following storage path: \"#{storage_path}\"."
41
+ files = files_in_repository.keep_if { |f| f.extension? '.pac' }
42
+ LocalPac.ui_logger.debug "Found the following files: \"#{files.join(", ")}\"."
43
+
44
+ files
45
+ end
46
+
47
+ def files_in_repository
48
+ head_commit = repository.lookup(repository.head.target)
49
+
50
+ files = []
51
+ head_commit.tree.walk_blobs(:postorder) do |root, entry|
52
+ files << file_creator.new("#{root}#{entry[:name]}", repository.lookup(entry[:oid]).content )
53
+ end
54
+
55
+ files
56
+ rescue Rugged::ReferenceError
57
+ []
58
+ end
59
+ end
60
+ end
@@ -16,8 +16,8 @@ module LocalPac
16
16
  LocalPac.ui_logger.info "Creating pid directory: #{::File.dirname(config.pid_file)}"
17
17
  Actions::CreateDirectory.new(::File.dirname(config.pid_file), force: options[:force]).run
18
18
 
19
- LocalPac.ui_logger.info "Creating log sink: #{config.log_sink}"
20
- Actions::CreateDirectory.new(config.log_sink, force: options[:force]).run
19
+ LocalPac.ui_logger.info "Creating log directory: #{::File.dirname(config.access_log)}"
20
+ Actions::CreateDirectory.new(::File.dirname(config.access_log), force: options[:force]).run
21
21
 
22
22
  LocalPac.ui_logger.info "Creating sass cache #{config.sass_cache}"
23
23
  Actions::CreateDirectory.new(config.sass_cache, force: options[:force]).run
@@ -26,10 +26,13 @@ module LocalPac
26
26
  Actions::CreateRepository.new(config.local_storage, bare: true, force: options[:force]).run
27
27
 
28
28
  LocalPac.ui_logger.info "Creating pre-receive hook in local storage \"#{config.local_storage}\"."
29
- Actions::CreateFile.new(:'git-hook', File.join(config.local_storage, 'hooks', 'pre-receive'), Data.new(config), force: options[:force], executable: true).run
29
+ Actions::CreateFile.new(:'git-hook', ::File.join(config.local_storage, 'hooks', 'pre-receive'), Data.new(config), force: options[:force], executable: true).run
30
30
 
31
- LocalPac.ui_logger.info "Creating example configuration."
32
- Actions::CreateOutput.new(:'example-config', $stdout, Data.new(LocalPac::Config.new)).run
31
+ LocalPac.ui_logger.info "Creating config file at \"#{config.config_file}\"."
32
+ Actions::CreateFile.new(:'example-config', config.config_file, Data.new(config), force: options[:force], create_directories: true).run
33
+
34
+ LocalPac.ui_logger.warn "Showing the configuration of local_pac on your system."
35
+ Actions::CreateOutput.new(:'example-config', $stdout, Data.new(config)).run
33
36
  end
34
37
  end
35
38
  end
@@ -3,19 +3,18 @@ module LocalPac
3
3
  class LocalStorage
4
4
  private
5
5
 
6
- attr_reader :storage, :null_file
6
+ attr_reader :storage
7
7
 
8
8
  public
9
9
 
10
- def initialize(storage = GitRepository.new(LocalPac.config.local_storage), null_file = NullPacFile.new )
10
+ def initialize(storage = GitStorage.new(LocalPac.config.local_storage))
11
11
  @storage = storage
12
- @null_file = null_file
13
12
  end
14
13
 
15
14
  def find(name)
16
15
  name = name.sub(/.pac$/, '').camelize.downcase.to_sym
17
16
  LocalPac.ui_logger.debug "Using the following name to find pac file: \":#{name}\"."
18
- storage[name] || null_file
17
+ storage[name]
19
18
  end
20
19
  end
21
20
  end
@@ -33,8 +33,8 @@ module LocalPac
33
33
  def routing
34
34
  routing_semaphore.synchronize do
35
35
  @routing ||= Rack::Builder.new do
36
- require_relative File.expand_path('../../../app/controllers/application_controller.rb', __FILE__)
37
- Dir.glob(File.expand_path('../../../app/controllers/*.rb', __FILE__)).each { |f| require_relative f }
36
+ require_relative ::File.expand_path('../../../app/controllers/application_controller.rb', __FILE__)
37
+ Dir.glob(::File.expand_path('../../../app/controllers/*.rb', __FILE__)).each { |f| require_relative f }
38
38
 
39
39
  map '/' do
40
40
  run LocalPac::App::FileServeController
@@ -1,10 +1,14 @@
1
1
  # encoding: utf-8
2
2
  module LocalPac
3
- class NullPacFile
3
+ class NullFile
4
4
  def path
5
5
  nil
6
6
  end
7
7
 
8
+ def extension
9
+ nil
10
+ end
11
+
8
12
  def name
9
13
  nil
10
14
  end
@@ -20,7 +20,7 @@ module LocalPac
20
20
  cmd << "-P #{LocalPac.config.pid_file}"
21
21
  cmd << "-o #{host}"
22
22
  cmd << "-p #{port}"
23
- cmd << File.expand_path('../../../config.ru', __FILE__)
23
+ cmd << ::File.expand_path('../../../config.ru', __FILE__)
24
24
 
25
25
  exec(cmd.join(" "))
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require_relative File.expand_path('../../../spec/support/git', __FILE__)
2
+ require_relative ::File.expand_path('../../../spec/support/git', __FILE__)
3
3
 
4
4
  module LocalPac
5
5
  class FileServeController
@@ -13,11 +13,11 @@ module LocalPac
13
13
  include FeduxOrg::Stdlib::Filesystem
14
14
 
15
15
  def root_directory
16
- File.expand_path('../../../', __FILE__)
16
+ ::File.expand_path('../../../', __FILE__)
17
17
  end
18
18
 
19
19
  def local_storage
20
- File.join(working_directory, 'git_repo', '.git')
20
+ ::File.join(working_directory, 'git_repo', '.git')
21
21
  end
22
22
  end.new
23
23
 
@@ -30,9 +30,10 @@ function FindProxyForURL(url, host) {
30
30
  EOS
31
31
  git_repo = 'git_repo'
32
32
 
33
- FileUtils.rm_rf File.join(working_directory, git_repo)
33
+ FileUtils.rm_rf ::File.join(working_directory, git_repo)
34
34
  git_init(git_repo)
35
- create_file(File.join(git_repo, 'file.pac'), valid_pac_file)
35
+ git_set_author(git_repo)
36
+ create_file(::File.join(git_repo, 'file.pac'), valid_pac_file)
36
37
  git_add(git_repo, 'file.pac')
37
38
  git_commit(git_repo)
38
39
  end
@@ -5,7 +5,7 @@ module LocalPac
5
5
  attr_reader :path
6
6
 
7
7
  def initialize(path)
8
- @path = File.expand_path(path)
8
+ @path = ::File.expand_path(path)
9
9
  end
10
10
 
11
11
  def name
@@ -7,13 +7,13 @@ module LocalPac
7
7
 
8
8
  public
9
9
 
10
- def initialize(root_directory = File.expand_path('../../../files', __FILE__), creator = TemplateFile)
11
- @root_directory = File.expand_path(root_directory)
10
+ def initialize(root_directory = ::File.expand_path('../../../files', __FILE__), creator = TemplateFile)
11
+ @root_directory = ::File.expand_path(root_directory)
12
12
  @creator = creator
13
13
  end
14
14
 
15
15
  def find(name)
16
- path = File.join(root_directory, "#{name.to_s}.erb")
16
+ path = ::File.join(root_directory, "#{name.to_s}.erb")
17
17
  fail Exceptions::ErbTemplateIsUnknown, "Template \"#{name}\" could not be found!" unless ::File.exist? path
18
18
 
19
19
  creator.new(path)
@@ -1,4 +1,4 @@
1
1
  #main LocalPac
2
2
  module LocalPac
3
- VERSION = '0.1.13'
3
+ VERSION = '0.2.0'
4
4
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = ::File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'local_pac/version'
5
5
 
@@ -16,20 +16,15 @@ EOS
16
16
  spec.license = "MIT"
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0")
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| ::File.basename(f) }
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_runtime_dependency 'sinatra'
24
23
  spec.add_runtime_dependency 'thor'
25
- spec.add_runtime_dependency 'activesupport'
24
+ spec.add_runtime_dependency 'sass'
25
+ spec.add_runtime_dependency 'haml'
26
26
  spec.add_runtime_dependency 'uglifier'
27
27
  spec.add_runtime_dependency 'therubyracer'
28
- spec.add_runtime_dependency 'pac'
29
- spec.add_runtime_dependency 'haml'
30
- spec.add_runtime_dependency 'sass'
31
- spec.add_runtime_dependency 'git_hook-pre_receive', '~>0.1.0'
32
- spec.add_runtime_dependency 'fedux_org-stdlib'
33
28
  spec.add_runtime_dependency 'bootstrap-sass'
34
29
  spec.add_runtime_dependency 'sprockets'
35
30
  spec.add_runtime_dependency 'sprockets-helpers'
@@ -38,4 +33,13 @@ EOS
38
33
  spec.add_runtime_dependency 'addressable'
39
34
  spec.add_runtime_dependency 'i18n'
40
35
  spec.add_runtime_dependency 'rack-contrib'
36
+ spec.add_runtime_dependency 'sinatra'
37
+ spec.add_runtime_dependency 'activesupport'
38
+ spec.add_runtime_dependency 'pac'
39
+ spec.add_runtime_dependency 'git_hook-pre_receive', '~>0.1.0'
40
+ spec.add_runtime_dependency 'facter'
41
+ spec.add_runtime_dependency 'pager'
42
+ spec.add_runtime_dependency 'sys-proctable'
43
+ spec.add_runtime_dependency 'rugged'
44
+ # spec.add_runtime_dependency 'fedux_org-stdlib'
41
45
  end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH << ::File.expand_path('../../lib', __FILE__)
4
4
 
5
5
  # Pull in all of the gems including those in the `test` group
6
6
  require 'bundler'
@@ -8,11 +8,14 @@ url="https://github.com/dg-vrnetze/${pkgname}"
8
8
  license=('MIT')
9
9
  depends=(ruby)
10
10
  install=${pkgname}.install
11
- makedepends=(rubygems filegen)
11
+ makedepends=(rubygems filegen phantomjs)
12
12
  source=(http://gems.rubyforge.org/gems/$pkgname-$pkgver.gem)
13
13
  noextract=($pkgname-$pkgver.gem)
14
14
  sha256sums=('cc2695dd44527e942a1d4cc3370480e1fbb44ff2eb3a050fe8714e371178ac39')
15
15
 
16
+ test() {
17
+ }
18
+
16
19
  package() {
17
20
  cd "$srcdir"
18
21
 
@@ -1,3 +1,3 @@
1
1
  ---
2
- :log_sink: /var/log/local_pac
2
+ :access_log: /var/log/local_pac/access.log
3
3
  :local_storage: /var/local_pac/data
@@ -10,7 +10,7 @@ describe Actions::CreateDirectory do
10
10
 
11
11
  context '#run' do
12
12
  it 'runs the action' do
13
- action = Actions::CreateDirectory.new(File.join(working_directory, 'repo'))
13
+ action = Actions::CreateDirectory.new(::File.join(working_directory, 'repo'))
14
14
  silence(:stderr) do
15
15
  action.run
16
16
  end
@@ -21,7 +21,7 @@ describe Actions::CreateDirectory do
21
21
  it 'respects existing path' do
22
22
  create_directory('repo')
23
23
 
24
- action = Actions::CreateDirectory.new(File.join(working_directory, 'repo'))
24
+ action = Actions::CreateDirectory.new(::File.join(working_directory, 'repo'))
25
25
 
26
26
  result = capture(:stderr) do
27
27
  LocalPac.ui_logger.level = ::Logger::INFO
@@ -34,7 +34,7 @@ describe Actions::CreateDirectory do
34
34
  it 'does not respect existing path if forced to' do
35
35
  create_directory('repo')
36
36
 
37
- action = Actions::CreateDirectory.new(File.join(working_directory, 'repo'), force: true)
37
+ action = Actions::CreateDirectory.new(::File.join(working_directory, 'repo'), force: true)
38
38
 
39
39
  result = capture(:stderr) do
40
40
  LocalPac.ui_logger.level = ::Logger::INFO
@@ -15,7 +15,7 @@ describe Actions::CreateFile do
15
15
  end
16
16
  end
17
17
 
18
- Actions::CreateFile.new(:template, File.join(working_directory, 'file'), {}, data, engine_klass, repository)
18
+ Actions::CreateFile.new(:template, ::File.join(working_directory, 'file'), {}, data, engine_klass, repository)
19
19
  end
20
20
  end
21
21
 
@@ -34,7 +34,7 @@ describe Actions::CreateFile do
34
34
  end
35
35
  end
36
36
 
37
- action = Actions::CreateFile.new(:template, File.join(working_directory, 'file'), data, {}, engine_klass, repository)
37
+ action = Actions::CreateFile.new(:template, ::File.join(working_directory, 'file'), data, {}, engine_klass, repository)
38
38
  silence(:stderr) do
39
39
  action.run
40
40
  end
@@ -42,6 +42,27 @@ describe Actions::CreateFile do
42
42
  expect(path_exists?('file')).to be_true
43
43
  end
44
44
 
45
+ it 'creates sub directories' do
46
+ repository = double('TemplateRepository')
47
+ expect(repository).to receive(:find).with(:template)
48
+
49
+ data = double('Data')
50
+
51
+ engine_klass = Class.new do
52
+ def initialize(data)
53
+ end
54
+
55
+ def compile(template, destination)
56
+ end
57
+ end
58
+
59
+ action = Actions::CreateFile.new(:template, ::File.join(working_directory, 'data', 'file'), data, {create_directories: true}, engine_klass, repository)
60
+ silence(:stderr) do
61
+ action.run
62
+ end
63
+
64
+ expect(path_exists?('data/file')).to be_true
65
+ end
45
66
  it 'respects existing path' do
46
67
  repository = double('TemplateRepository')
47
68
 
@@ -10,7 +10,7 @@ describe Actions::CreateRepository do
10
10
 
11
11
  context '#run' do
12
12
  it 'runs the action' do
13
- action = Actions::CreateRepository.new(File.join(working_directory, 'repo'))
13
+ action = Actions::CreateRepository.new(::File.join(working_directory, 'repo'))
14
14
  silence(:stderr) do
15
15
  action.run
16
16
  end
@@ -21,7 +21,7 @@ describe Actions::CreateRepository do
21
21
  it 'respects existing path' do
22
22
  create_directory('repo')
23
23
 
24
- action = Actions::CreateRepository.new(File.join(working_directory, 'repo'))
24
+ action = Actions::CreateRepository.new(::File.join(working_directory, 'repo'))
25
25
 
26
26
  result = capture(:stderr) do
27
27
  LocalPac.ui_logger.level = ::Logger::INFO
@@ -34,7 +34,7 @@ describe Actions::CreateRepository do
34
34
  it 'does not respect existing path if forced to' do
35
35
  create_directory('repo')
36
36
 
37
- action = Actions::CreateRepository.new(File.join(working_directory, 'repo'), force: true)
37
+ action = Actions::CreateRepository.new(::File.join(working_directory, 'repo'), force: true)
38
38
 
39
39
  result = capture(:stderr) do
40
40
  LocalPac.ui_logger.level = ::Logger::INFO
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::GetSystemInformation do
5
+ context '#initialize' do
6
+ it 'has no special requirements' do
7
+ expect {
8
+ Actions::GetSystemInformation.new
9
+ }.not_to raise_error
10
+ end
11
+ end
12
+
13
+ context '#run' do
14
+ it 'gathers all relevant information and prints them to stdout' do
15
+ result = capture(:stdout) do
16
+ Actions::GetSystemInformation.new.run
17
+ end
18
+
19
+ expect(result).to include('osfamily')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::PrintNewline do
5
+ context '#initialize' do
6
+ it 'has no special requirements' do
7
+ expect {
8
+ Actions::PrintNewline.new
9
+ }.not_to raise_error
10
+ end
11
+
12
+ it 'accepts a count' do
13
+ expect {
14
+ Actions::PrintNewline.new(2)
15
+ }.not_to raise_error
16
+ end
17
+ end
18
+
19
+ context '#run' do
20
+ it 'prints 1 newline' do
21
+ result = capture(:stdout) do
22
+ Actions::PrintNewline.new.run
23
+ end
24
+
25
+ expect(result).to eq("\n")
26
+ end
27
+
28
+ it 'prints 2 newlines' do
29
+ result = capture(:stdout) do
30
+ Actions::PrintNewline.new(2).run
31
+ end
32
+
33
+ expect(result).to eq("\n\n")
34
+ end
35
+ end
36
+ end