local_pac 0.2.3 → 0.3.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.
data/Gemfile CHANGED
@@ -18,7 +18,6 @@ group :test do
18
18
  end
19
19
 
20
20
  group :development do
21
- gem 'awesome_print', require: false
22
21
  gem 'debugger'
23
22
  gem 'debugger-completion'
24
23
  gem 'foreman', require: false
@@ -29,6 +28,7 @@ group :development do
29
28
  gem 'redcarpet', require: false
30
29
  gem 'tmrb', require: false
31
30
  gem 'yard', require: false
31
+ gem 'inch', require: false
32
32
  end
33
33
 
34
34
  group :profile do
@@ -42,8 +42,10 @@ gem 'erubis', group: [:development, :test]
42
42
  gem 'versionomy', group: [:development, :test], require: false
43
43
  gem 'activesupport', '~> 4.0.0', group: [:development, :test], require: false
44
44
 
45
- #group :webserver do
46
- # group :puma do
47
- # gem 'puma'
48
- # end
49
- #end
45
+ gem 'awesome_print', group: [:development, :test], require: 'ap'
46
+
47
+ group :webserver do
48
+ group :puma do
49
+ gem 'puma'
50
+ end
51
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- local_pac (0.2.2)
4
+ local_pac (0.2.3)
5
5
  activesupport
6
6
  addressable
7
7
  bootstrap-sass
@@ -108,6 +108,10 @@ GEM
108
108
  tilt
109
109
  hike (1.2.3)
110
110
  i18n (0.6.9)
111
+ inch (0.3.1)
112
+ sparkr (>= 0.2.0)
113
+ term-ansicolor
114
+ yard (~> 0.8.7)
111
115
  json (1.8.1)
112
116
  libv8 (3.16.14.3)
113
117
  method_source (0.8.2)
@@ -139,6 +143,8 @@ GEM
139
143
  pry-doc (0.5.1)
140
144
  pry (>= 0.9)
141
145
  yard (>= 0.8)
146
+ puma (2.7.1)
147
+ rack (>= 1.1, < 2.0)
142
148
  rack (1.5.2)
143
149
  rack-contrib (1.1.0)
144
150
  rack (>= 0.9.1)
@@ -179,6 +185,7 @@ GEM
179
185
  rack-protection (~> 1.4)
180
186
  tilt (~> 1.3, >= 1.3.4)
181
187
  slop (3.4.7)
188
+ sparkr (0.4.1)
182
189
  sprockets (2.10.1)
183
190
  hike (~> 1.2)
184
191
  multi_json (~> 1.0)
@@ -232,11 +239,13 @@ DEPENDENCIES
232
239
  foreman
233
240
  fuubar
234
241
  github-markup
242
+ inch
235
243
  local_pac!
236
244
  poltergeist
237
245
  pry
238
246
  pry-debugger
239
247
  pry-doc
248
+ puma
240
249
  rack-test
241
250
  rake
242
251
  redcarpet
data/README.md CHANGED
@@ -97,7 +97,7 @@ makepkg -is
97
97
  % firefox http://localhost:8000/v1/lookup/proxy.pac
98
98
  ```
99
99
 
100
- ### Getting started
100
+ ### Getting started (Work in Progress)
101
101
 
102
102
  Make sure that you place a config file for `local_pac` in one of the following
103
103
  places or let `local_pac` generate a file on default values (see below).
@@ -310,6 +310,10 @@ option | value
310
310
  A good website to support you writing proxy.pac-files is:
311
311
  http://findproxyforurl.com.
312
312
 
313
+ ## Documentation
314
+
315
+ http://www.rubydoc.info/github/dg-vrnetze/local_pac/frames
316
+
313
317
  ## Future
314
318
 
315
319
  * Improve API to support further functionality
data/bin/local_pac CHANGED
@@ -18,6 +18,7 @@ module LocalPac
18
18
  option :access_log, type: :string, desc: 'File to write access log to'
19
19
  option :listen, type: :string, default: 'tcp://localhost:8000', desc: 'Listen for requests'
20
20
  option :rack_environment, type: :string, default: 'production', desc: 'Rack environment for application'
21
+ option :with, type: :string, default: 'puma', desc: 'Server used to serve proxy pac'
21
22
  def serve
22
23
  LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file]
23
24
  LocalPac.config.access_log = options[:access_log] if options[:access_log]
@@ -30,7 +31,21 @@ module LocalPac
30
31
  LocalPac.ui_logger.debug('Options: ' + options.to_s)
31
32
  LocalPac.ui_logger.debug("Config:\n" + LocalPac.config.to_s)
32
33
 
33
- Server.new(options[:listen], options[:rack_environment]).start
34
+ command_klass = case options[:with].to_sym
35
+ when :puma
36
+ ServerCommands::Puma
37
+ when :rackup
38
+ ServerCommands::Rackup
39
+ else
40
+ ServerCommands::Rackup
41
+ end
42
+
43
+ command = command_klass.new(
44
+ listen: options[:listen],
45
+ environment: options[:rack_environment],
46
+ )
47
+
48
+ Server.new(command).start
34
49
  end
35
50
 
36
51
  desc 'init', 'Create files/directories to use local_pac in dir or $PWD'
data/lib/local_pac.rb CHANGED
@@ -55,6 +55,8 @@ require 'local_pac/actions/print_title'
55
55
  require 'local_pac/actions/reload_configuration'
56
56
  require 'local_pac/actions/reload_local_storage'
57
57
  require 'local_pac/actions/add_examples_to_local_storage'
58
+ require 'local_pac/server_commands/rackup'
59
+ require 'local_pac/server_commands/puma'
58
60
  require 'local_pac/cli/helper'
59
61
  require 'local_pac/cli/reload'
60
62
  require 'local_pac/initializer'
@@ -1,28 +1,19 @@
1
1
  # encoding:utf-8
2
2
  module LocalPac
3
3
  class Server
4
- attr_reader :port, :host, :path, :environment
5
4
 
6
- def initialize(listen, environment = 'development')
7
- uri = URI.parse(listen)
5
+ private
8
6
 
9
- @port = uri.port
10
- @host = uri.host
11
- @environment = environment
12
- rescue => e
13
- fail Exceptions::ServerListenStatementInvalid, "I cannot parse the listen statement: #{listen}. It is invalid: #{e.message}"
7
+ attr_reader :command
8
+
9
+ public
10
+
11
+ def initialize(command = ServerCommands::Rackup.new)
12
+ @command = command
14
13
  end
15
14
 
16
15
  def start
17
- cmd = []
18
- cmd << 'rackup'
19
- cmd << "-E #{environment}"
20
- cmd << "-P #{LocalPac.config.pid_file}"
21
- cmd << "-o #{host}"
22
- cmd << "-p #{port}"
23
- cmd << ::File.expand_path('../../../config.ru', __FILE__)
24
-
25
- exec(cmd.join(" "))
16
+ exec command.to_s
26
17
  end
27
18
  end
28
19
  end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module ServerCommands
4
+ class Puma
5
+
6
+ private
7
+
8
+ attr_reader :environment, :pid_file, :config_file, :listen, :worker_count
9
+
10
+ public
11
+
12
+ def initialize(options = {})
13
+ @environment = options.fetch(:environment, :development)
14
+ @pid_file = options.fetch(:pid_file, LocalPac.config.pid_file)
15
+ @config_file = options.fetch(:config_file, ::File.expand_path('../../../../config.ru', __FILE__))
16
+ @listen = options.fetch(:listen, 'tcp://127.0.0.1:8080')
17
+ @worker_count = options.fetch(:worker_count, nil)
18
+
19
+ rescue KeyError => e
20
+ raise ArgumentError, e.message
21
+ end
22
+
23
+ def to_s
24
+ cmd = []
25
+
26
+ cmd << 'puma'
27
+ cmd << "-e #{environment}" if environment
28
+ cmd << "--pidfile #{pid_file}" if pid_file
29
+ cmd << "-b #{listen}" if listen
30
+ cmd << "-w #{worker_count}" if worker_count
31
+ cmd << config_file if config_file
32
+
33
+ cmd.join(" ")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module ServerCommands
4
+ class Rackup
5
+
6
+ private
7
+
8
+ attr_reader :environment, :pid_file, :config_file, :host, :port
9
+
10
+ public
11
+
12
+ def initialize(options = {})
13
+ @environment = options.fetch(:environment, :development)
14
+ @pid_file = options.fetch(:pid_file, LocalPac.config.pid_file)
15
+ @config_file = options.fetch(:config_file, ::File.expand_path('../../../../config.ru', __FILE__))
16
+ listen = options.fetch(:listen, '127.0.0.1:8080')
17
+
18
+ begin
19
+ uri = Addressable::URI.heuristic_parse(listen)
20
+ rescue StandardError => e
21
+ fail Exceptions::ServerListenStatementInvalid, "I cannot parse the listen statement: #{listen}. It is invalid: #{e.message}"
22
+ end
23
+
24
+ @port = uri.port
25
+ @host = uri.host
26
+ rescue KeyError => e
27
+ raise ArgumentError, e.message
28
+ end
29
+
30
+ def to_s
31
+ cmd = []
32
+
33
+ cmd << 'rackup'
34
+ cmd << "-E #{environment}" if environment
35
+ cmd << "-P #{pid_file}" if pid_file
36
+ cmd << "-o #{host}" if host
37
+ cmd << "-p #{port}" if port
38
+ cmd << config_file if config_file
39
+
40
+ cmd.join(" ")
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,4 +1,4 @@
1
1
  #main LocalPac
2
2
  module LocalPac
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -3,3 +3,5 @@ clean:
3
3
  rm -f *.src.tar.gz
4
4
  rm -f *.pkg.tar.xz
5
5
  rm -f *.gem
6
+ rm -rf src
7
+ rm -rf pkg
@@ -34,10 +34,12 @@ package() {
34
34
 
35
35
  msg "Starting download of gems. Don't get alert if the download takes a lot of time. Since rubygems 2.2.0 a new algorithm to resolve dependencies is used. Upgrade to > 2.2.0 via sudo /usr/bin/gem update --system to improve performance."
36
36
 
37
- GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} $pkgname puma
37
+ GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} $pkgname -v $pkgver
38
+ GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} puma
38
39
 
39
40
  install -D -m 644 ${pkgdir}${_share_dir}/archlinux/config.yaml ${pkgdir}${_examples_dir}/config.yaml.example
40
41
 
42
+ set -x
41
43
  SOFTWARE_BINARY=$_library_dir/gems/${pkgname}-${pkgver}/bin/${pkgname} SOFTWARE_LIB=/usr/lib/local_pac filegen ${pkgdir}${_share_dir}/archlinux/startup.erb > ${pkgdir}${_bin_dir}/${pkgname}
42
44
 
43
45
  chmod a+x ${pkgdir}/${_bin_dir}/${pkgname}
@@ -4,4 +4,6 @@ export GEM_ROOT='<%= lookup('SOFTWARE_LIB') %>'
4
4
  export GEM_PATH='<%= lookup('SOFTWARE_LIB') %>'
5
5
  export GEM_HOME='<%= lookup('SOFTWARE_LIB') %>'
6
6
 
7
+ export PATH="<%= lookup('SOFTWARE_LIB') %>/bin"
8
+
7
9
  exec <%= lookup('SOFTWARE_BINARY') %> $*
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ describe ServerCommands::Puma do
3
+
4
+ context '#initialize' do
5
+ it 'requires a listen statement' do
6
+ pid_file = create_file 'pid', $$
7
+ config_file = create_file 'config.ru'
8
+
9
+ expect {
10
+ ServerCommands::Puma.new(
11
+ listen: 'localhost:8080',
12
+ pid_file: pid_file,
13
+ config_file: config_file,
14
+ )
15
+ }.not_to raise_error
16
+ end
17
+ end
18
+
19
+ context '#to_s' do
20
+ it 'has defaults' do
21
+ command = ServerCommands::Puma.new
22
+ expect(command.to_s).to eq("puma -e development --pidfile #{LocalPac.config.pid_file} -b tcp://127.0.0.1:8080 #{File.expand_path('../../../config.ru', __FILE__)}")
23
+ end
24
+
25
+ it 'respects changed environment' do
26
+ command = ServerCommands::Puma.new(
27
+ environment: 'super_env'
28
+ )
29
+
30
+ expect(command.to_s).to include('-e super_env')
31
+ end
32
+
33
+ it 'respects changed pid file' do
34
+ pid_file = create_file 'pid', $$
35
+
36
+ command = ServerCommands::Puma.new(
37
+ pid_file: pid_file,
38
+ )
39
+
40
+ expect(command.to_s).to include("--pidfile #{pid_file}")
41
+ end
42
+
43
+ it 'respects changed config_file' do
44
+ config_file = create_file 'config.ru'
45
+
46
+ command = ServerCommands::Puma.new(
47
+ config_file: config_file,
48
+ )
49
+
50
+ expect(command.to_s).to include(config_file)
51
+ end
52
+
53
+ it 'respects changed worker count' do
54
+ command = ServerCommands::Puma.new(
55
+ worker_count: 20,
56
+ )
57
+
58
+ expect(command.to_s).to include('-w 20')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ describe ServerCommands::Rackup do
3
+
4
+ context '#initialize' do
5
+ it 'requires a listen statement' do
6
+ pid_file = create_file 'pid', $$
7
+ config_file = create_file 'config.ru'
8
+
9
+ expect {
10
+ ServerCommands::Rackup.new(
11
+ listen: 'localhost:8080',
12
+ pid_file: pid_file,
13
+ config_file: config_file,
14
+ )
15
+ }.not_to raise_error
16
+ end
17
+ end
18
+
19
+ context '#to_s' do
20
+ it 'has defaults' do
21
+ command = ServerCommands::Rackup.new
22
+ expect(command.to_s).to eq("rackup -E development -P #{LocalPac.config.pid_file} -o 127.0.0.1 -p 8080 #{File.expand_path('../../../config.ru', __FILE__)}")
23
+ end
24
+
25
+ it 'respects changed environment' do
26
+ command = ServerCommands::Rackup.new(
27
+ environment: '-E super_env'
28
+ )
29
+
30
+ expect(command.to_s).to include('-E super_env')
31
+ end
32
+
33
+ it 'respects changed pid file' do
34
+ pid_file = create_file 'pid', $$
35
+
36
+ command = ServerCommands::Rackup.new(
37
+ pid_file: pid_file,
38
+ )
39
+
40
+ expect(command.to_s).to include("-P #{pid_file}")
41
+ end
42
+
43
+ it 'respects changed config_file' do
44
+ config_file = create_file 'config.ru'
45
+
46
+ command = ServerCommands::Rackup.new(
47
+ config_file: config_file,
48
+ )
49
+
50
+ expect(command.to_s).to include(config_file)
51
+ end
52
+ end
53
+ end
data/spec/server_spec.rb CHANGED
@@ -3,16 +3,70 @@ require 'spec_helper'
3
3
 
4
4
  describe Server do
5
5
  context '#initialize' do
6
- it 'requires listen statement' do
6
+ it 'requires a command' do
7
+ command = double('Command')
8
+
7
9
  expect {
8
- Server.new('tcp://locahost:8000')
10
+ Server.new(command)
9
11
  }.not_to raise_error
10
12
  end
11
13
 
12
- it 'fails on invalid listen statement' do
14
+ it 'uses rackup by default' do
13
15
  expect {
14
- Server.new(nil)
15
- }.to raise_error Exceptions::ServerListenStatementInvalid
16
+ Server.new
17
+ }.not_to raise_error
18
+ end
19
+ end
20
+
21
+ context '#start' do
22
+ it 'starts the server' do
23
+ create_file 'app.rb', <<-EOS.strip_heredoc
24
+ require 'sinatra'
25
+
26
+ trap 'USR1' do
27
+ $stderr.puts "Exit"
28
+ Kernel.exit!
29
+ end
30
+
31
+ class App < Sinatra::Base
32
+ get '/' do
33
+ 'Hello World'
34
+ end
35
+ end
36
+ EOS
37
+
38
+ config_file = create_file 'config.ru', <<-EOS.strip_heredoc
39
+ $LOAD_PATH << File.expand_path('..', __FILE__)
40
+
41
+ #$stderr = StringIO.new
42
+ #$stdout = StringIO.new
43
+
44
+ require 'app'
45
+ run App
46
+ EOS
47
+
48
+ command = double('Command')
49
+ allow(command).to receive(:to_s).and_return("rackup -E development -o 127.0.0.1 -p 9999 #{config_file} 2>/dev/null >&1")
50
+
51
+ server = Server.new(command)
52
+
53
+ unless child_pid = Kernel.fork
54
+ server.start
55
+ end
56
+
57
+ begin
58
+ tries ||= 3
59
+
60
+ response = with_environment({}, clear: true) do
61
+ Excon.get('http://127.0.0.1:9999')
62
+ end
63
+ rescue Excon::Errors::SocketError
64
+ sleep 1
65
+ retry unless (tries -= 1).zero?
66
+ end
67
+
68
+ Process.kill :USR1, child_pid
69
+ expect(response.body).to eq('Hello World')
16
70
  end
17
71
  end
18
72
  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.2.3
4
+ version: 0.3.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-22 00:00:00.000000000 Z
12
+ date: 2014-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -485,6 +485,8 @@ files:
485
485
  - lib/local_pac/router.rb
486
486
  - lib/local_pac/runner.rb
487
487
  - lib/local_pac/server.rb
488
+ - lib/local_pac/server_commands/puma.rb
489
+ - lib/local_pac/server_commands/rackup.rb
488
490
  - lib/local_pac/spec_helper.rb
489
491
  - lib/local_pac/spec_helper_file_server.rb
490
492
  - lib/local_pac/template_file.rb
@@ -537,6 +539,8 @@ files:
537
539
  - spec/proxy_pac/pac_result_spec.rb
538
540
  - spec/proxy_pac_result_parser_spec.rb
539
541
  - spec/runner_spec.rb
542
+ - spec/server_commands/puma_spec.rb
543
+ - spec/server_commands/rackup_spec.rb
540
544
  - spec/server_spec.rb
541
545
  - spec/spec_helper.rb
542
546
  - spec/spec_helper_features.rb
@@ -617,6 +621,8 @@ test_files:
617
621
  - spec/proxy_pac/pac_result_spec.rb
618
622
  - spec/proxy_pac_result_parser_spec.rb
619
623
  - spec/runner_spec.rb
624
+ - spec/server_commands/puma_spec.rb
625
+ - spec/server_commands/rackup_spec.rb
620
626
  - spec/server_spec.rb
621
627
  - spec/spec_helper.rb
622
628
  - spec/spec_helper_features.rb