adsf 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 30bf98446c4011646d9a41618ee9cb1f4da0b6a0
4
- data.tar.gz: 7630399b32f0ac05c1e4108608bc8112fca81287
2
+ SHA256:
3
+ metadata.gz: 18fe44d3963307d81690a262c5fb57d06fed10e560499dac1fc9f8d1bacd9596
4
+ data.tar.gz: dc1fc182824d28cb9d6cf532fe52b2681ba95bd9e3f6508008d70165c4b9a9b7
5
5
  SHA512:
6
- metadata.gz: 42e186eb4bdb29a97675ba72c53d71eed7d7742dfa1e155b4ecdd7969101f73b089f809f91bd041181e7703d1fa8460c6a59892b5130241c6925e8fcb527c2f8
7
- data.tar.gz: 160446420d76dd484ff674c95d8be0ca828f2a75edc103683828ea28528c4bb161c5608f9c096d5a8ff110f9711e9f352be099e624893caa92a3d920e482ca45
6
+ metadata.gz: 06f8d4b5a752c387cc7b36a1edf4ed00fd934d3201bafcbbffb565da3f6707c75aebe47eb34c408e3ee8be6689a5cf9da424aa93f78b30932885458c433b7529
7
+ data.tar.gz: 3679850b8b89c0944ea9267396c3ea90e41e10ac7221aed043990e8e400730ce556b093009bc91afbfafd501e38347253cc6e713146d4eade053511cf7e05e2d
data/Gemfile CHANGED
@@ -1,13 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rack'
3
+ gemspec
4
4
 
5
5
  group :development do
6
- gem 'rake'
7
- end
8
-
9
- group :testing do
10
- gem 'mocha'
11
- gem 'rack-test'
6
+ gem 'codecov', require: false
7
+ gem 'm'
12
8
  gem 'minitest'
9
+ gem 'rack-test'
10
+ gem 'rake'
11
+ gem 'rubocop'
13
12
  end
@@ -1,24 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ adsf (1.3.0)
5
+ rack (>= 1.0.0, < 3.0.0)
6
+
1
7
  GEM
2
8
  remote: https://rubygems.org/
3
9
  specs:
4
- metaclass (0.0.4)
5
- minitest (5.8.4)
6
- mocha (1.1.0)
7
- metaclass (~> 0.0.1)
8
- rack (1.6.4)
9
- rack-test (0.6.3)
10
- rack (>= 1.0)
11
- rake (11.1.1)
10
+ ast (2.3.0)
11
+ codecov (0.1.10)
12
+ json
13
+ simplecov
14
+ url
15
+ docile (1.1.5)
16
+ json (2.1.0)
17
+ m (1.5.1)
18
+ method_source (>= 0.6.7)
19
+ rake (>= 0.9.2.2)
20
+ method_source (0.9.0)
21
+ minitest (5.10.3)
22
+ parallel (1.12.0)
23
+ parser (2.4.0.2)
24
+ ast (~> 2.3)
25
+ powerpack (0.1.1)
26
+ rack (2.0.3)
27
+ rack-test (0.7.0)
28
+ rack (>= 1.0, < 3)
29
+ rainbow (2.2.2)
30
+ rake
31
+ rake (12.3.0)
32
+ rubocop (0.51.0)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.3.3.1, < 3.0)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 2.2.2, < 3.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ ruby-progressbar (1.9.0)
40
+ simplecov (0.15.1)
41
+ docile (~> 1.1.0)
42
+ json (>= 1.8, < 3)
43
+ simplecov-html (~> 0.10.0)
44
+ simplecov-html (0.10.2)
45
+ unicode-display_width (1.3.0)
46
+ url (0.3.2)
12
47
 
13
48
  PLATFORMS
14
49
  ruby
15
50
 
16
51
  DEPENDENCIES
52
+ adsf!
53
+ codecov
54
+ m
17
55
  minitest
18
- mocha
19
- rack
20
56
  rack-test
21
57
  rake
58
+ rubocop
22
59
 
23
60
  BUNDLED WITH
24
- 1.11.2
61
+ 1.16.0
data/NEWS.md CHANGED
@@ -1,32 +1,31 @@
1
- adsf News
2
- =========
1
+ # adsf News
3
2
 
4
- 1.2.1
5
- -----
3
+ ## 1.3.0 (2017-11-19)
4
+
5
+ Features:
6
+
7
+ * Added `Adsf::Server`
8
+
9
+ ## 1.2.1
6
10
 
7
11
  * Fixed compatibility with Ruby 2.3.0 (#3) [Vipul Amler]
8
12
 
9
- 1.2.0
10
- -----
13
+ ## 1.2.0
11
14
 
12
- * Add `--local-only` and `--listen-address` options (#1) [Ed Brannin]
15
+ * Added `--local-only` and `--listen-address` options (#1) [Ed Brannin]
13
16
 
14
- 1.1.1
15
- -----
17
+ ## 1.1.1
16
18
 
17
19
  * Made SIGINT/SIGTERM cause proper exit
18
20
 
19
- 1.1.0
20
- -----
21
+ ## 1.1.0
21
22
 
22
23
  * Added support for custom index filenames [Mark Meves]
23
24
 
24
- 1.0.1
25
- -----
25
+ ## 1.0.1
26
26
 
27
27
  * Added runtime dependency on Rack
28
28
 
29
- 1.0
30
- ---
29
+ ## 1.0.0
31
30
 
32
31
  * Initial release
data/README.md CHANGED
@@ -1,7 +1,13 @@
1
+ [![Gem version](https://img.shields.io/gem/v/adsf.svg)](http://rubygems.org/gems/adsf)
2
+ [![Gem downloads](https://img.shields.io/gem/dt/adsf.svg)](http://rubygems.org/gems/adsf)
3
+ [![Build status](https://img.shields.io/travis/ddfreyne/adsf.svg)](https://travis-ci.org/ddfreyne/adsf)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/ddfreyne/adsf.svg)](https://codeclimate.com/github/ddfreyne/adsf)
5
+ [![Code Coverage](https://img.shields.io/codecov/c/github/ddfreyne/adsf.svg)](https://codecov.io/gh/ddfreyne/adsf)
6
+
1
7
  adsf
2
8
  ====
3
9
 
4
- adsf (A Dead Simple Fileserver) is a tiny static file server that you can launch instantly in any directory, like this:
10
+ _adsf_ (**A** **D**ead **S**imple **F**ileserver) is a tiny static web server that you can launch instantly in any directory, like this:
5
11
 
6
12
  ▸ ls -l
7
13
  total 0
@@ -11,34 +17,60 @@ adsf (A Dead Simple Fileserver) is a tiny static file server that you can launch
11
17
  drwxr-xr-x 2 ddfreyne staff 68 May 29 10:04 projects
12
18
 
13
19
  ▸ adsf
14
- [2009-05-29 10:04:44] INFO WEBrick 1.3.1
15
- [2009-05-29 10:04:44] INFO ruby 1.8.7 (2008-08-11) [i686-darwin9.6.1]
16
- [2009-05-29 10:04:44] INFO WEBrick::HTTPServer#start: pid=2757 port=3000
20
+ [2017-11-19 11:49:20] INFO WEBrick 1.3.1
21
+ [2017-11-19 11:49:20] INFO ruby 2.4.2 (2017-09-14) [x86_64-darwin17]
22
+ [2017-11-19 11:49:20] INFO WEBrick::HTTPServer#start: pid=95218 port=3000
17
23
 
18
24
  … and now you can go to http://localhost:3000/ and start browsing.
19
25
 
20
- You can specify a custom web root with `-r` or `--root`; the server will be started in that directory (e.g. `adsf -r public/`). If you want to specificy custom index filenames (other than the default `index.html`), you can use the `-i` or `--index-filename` option, which is a comma-separated list of filenames (e.g. `adsf -i index.html,index.xml`).
21
-
22
- adsf has one dependency, namely on Rack. It is licenced under the MIT license. Patches are always welcome; check my contact e-mail address at the bottom of this document.
26
+ See `adsf --help` for details.
23
27
 
24
28
  Using adsf programmatically
25
29
  ---------------------------
26
30
 
27
- You can use adsf programmatically in your Rack applications. [nanoc](http://nanoc.stoneship.org/) uses adsf for its “view” command, for example. adsf consists of one middleware class that finds index filenames, and rewrites these requests so that Rack::File can be used to serve these files.
31
+ ### IndexFileFinder
32
+
33
+ The `Adsf::Rack::IndexFileFinder` middleware makes Rack load an index file (e.g. `index.html`) when requesting a directory. For example, the following runs a web server with the 'public' directory as its web root:
28
34
 
29
- Here’s an example middleware/application stack that runs a web server with the "public/" directory as its web root:
35
+ ```ruby
36
+ use Adsf::Rack::IndexFileFinder, root: 'public'
37
+ run Rack::File.new('public')
38
+ ```
30
39
 
31
- use Adsf::Rack::IndexFileFinder, :root => "public/"
32
- run Rack::File.new("public/")
40
+ It takes the following options:
33
41
 
34
- The `:root` option is required; it should contain the path to the web root.
42
+ * `root` (required): the path to the web root
35
43
 
36
- You can also specify an `:index_filenames` option, containing the names of the index filenames that will be served when a directory containing an index file is requested. Usually, this will simply be `[ 'index.html' ]`, but under different circumstances (when using IIS, for exmaple), the array may have to be modified to include index filenames such as `default.html` or `index.xml`. Here’s an example middleware/application stack that uses custom index filenames:
44
+ * `index_filenames` (optional; defaults to `['index.html']`): contains the names of the index filenames that will be served when a directory containing an index file is requested. Usually, this will simply be `['index.html']`, but under different circumstances (when using IIS, for example), the array may have to be modified to include index filenames such as `default.html` or `index.xml`. Here’s an example middleware/application stack that uses custom index filenames:
37
45
 
46
+ ```ruby
38
47
  use Adsf::Rack::IndexFileFinder,
39
- :root => "public/",
40
- :index_filenames => %w( index.html index.xhtml index.xml )
41
- run Rack::File.new("public/")
48
+ root: 'public',
49
+ index_filenames: %w[index.html index.xhtml]
50
+ run Rack::File.new('public')
51
+ ```
52
+
53
+ ### Server
54
+
55
+ `Adsf::Server` runs a web server programmatically. For example:
56
+
57
+ ```ruby
58
+ server = Adsf::Server.new(root: 'public')
59
+
60
+ %w[INT TERM].each do |s|
61
+ Signal.trap(s) { server.stop }
62
+ end
63
+
64
+ server.run
65
+ ```
66
+
67
+ It takes the following options:
68
+
69
+ * `root` (required): the path to the web root
70
+ * `index_filenames` (optional; defaults to `['index.html']`): (see above)
71
+ * `host` (optional; defaults to `'127.0.0.1'`): the address of the network interface to listen on
72
+ * `port` (optional; defaults to `3000`): the port ot listen on
73
+ * `handler` (optional): the Rack handler to use
42
74
 
43
75
  Contributors
44
76
  ------------
@@ -46,8 +78,4 @@ Contributors
46
78
  * Ed Brannin
47
79
  * Larissa Reis
48
80
  * Mark Meves
49
-
50
- Contact
51
- -------
52
-
53
- You can reach me at <denis.defreyne@stoneship.org>.
81
+ * Vipul Amler
data/Rakefile CHANGED
@@ -1,16 +1,12 @@
1
- # Load adsf
2
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
3
- require 'adsf'
1
+ require 'rubocop/rake_task'
2
+ require 'rake/testtask'
4
3
 
5
- desc 'Run all tests'
6
- task :test do
7
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
8
-
9
- require 'minitest/autorun'
10
- MiniTest.autorun
11
-
12
- test_files = Dir["test/**/test_*.rb"]
13
- test_files.each { |f| require f }
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.test_files = Dir['test/**/test_*.rb']
6
+ t.libs << 'test'
7
+ t.verbose = false
14
8
  end
15
9
 
16
- task :default => :test
10
+ RuboCop::RakeTask.new(:rubocop)
11
+
12
+ task default: %i[test rubocop]
data/bin/adsf CHANGED
@@ -1,83 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
-
5
- require 'rack'
6
3
  require 'optparse'
7
4
  require 'adsf'
8
5
 
9
- # Parse options
10
6
  options = {
11
- :handler => nil,
12
- :port => 3000,
13
- :index_filenames => %w( index.html ),
14
- :root => '.',
15
- :host => '0.0.0.0',
7
+ handler: nil,
8
+ port: 3000,
9
+ index_filenames: %w[index.html],
10
+ root: '.',
11
+ host: '0.0.0.0'
16
12
  }
17
- OptionParser.new do |opts|
18
- opts.banner = "Usage: adsf [options]"
19
13
 
20
- opts.separator ''
21
- opts.separator 'Specific options:'
14
+ OptionParser.new do |opts|
15
+ opts.banner = 'Usage: adsf [options]'
22
16
 
23
- # handler
24
17
  opts.on('-H', '--handler [handler]', 'Specify the handler to use') do |o|
25
18
  options[:handler] = o
26
19
  end
27
20
 
28
- # help
29
- opts.on('-h', '--help', 'Display help') do |o|
21
+ opts.on('-h', '--help', 'Display help') do |_o|
30
22
  puts opts
31
23
  exit
32
24
  end
33
25
 
34
- # index filenames
35
26
  opts.on('-i', '--index-filenames [index-filenames]', 'Specify index filenames (comma-separated)') do |o|
36
27
  options[:index_filenames] = o.split(',')
37
28
  end
38
29
 
39
- # port
40
30
  opts.on('-p', '--port [port]', Integer, 'Specify the port number to use') do |o|
41
31
  options[:port] = o
42
32
  end
43
33
 
44
- # root
45
34
  opts.on('-r', '--root [root]', 'Specify the web root to use') do |o|
46
35
  options[:root] = o
47
36
  end
48
37
 
49
- # host
50
38
  opts.on('-l', '--local-only', 'Only listen to requests from localhost (short for "-a localhost")') do
51
39
  options[:host] = 'localhost'
52
40
  end
53
41
 
54
- # host
55
42
  opts.on('-a', '--listen-address [host]', 'Specify the address to listen to') do |o|
56
43
  options[:host] = o
57
44
  end
58
45
  end.parse!
59
46
 
60
- # Find handler
61
- handler = Rack::Handler.get(options[:handler])
62
- if handler.nil?
63
- handler = Rack::Handler::WEBrick
64
- end
65
-
66
- # Create app
67
- app = Rack::Builder.new do
68
- use Rack::CommonLogger
69
- use Rack::ShowExceptions
70
- use Rack::Lint
71
- use Adsf::Rack::IndexFileFinder,
72
- :root => options[:root],
73
- :index_filenames => options[:index_filenames]
74
- run Rack::File.new(options[:root])
75
- end.to_app
47
+ server = Adsf::Server.new(options)
76
48
 
77
- # Be quittable
78
- %w( INT TERM ).each do |s|
79
- Signal.trap(s) { handler.shutdown }
49
+ %w[INT TERM].each do |s|
50
+ Signal.trap(s) { server.stop }
80
51
  end
81
52
 
82
- # Run
83
- handler.run(app, :Port => options[:port], :Host => options[:host])
53
+ server.run
@@ -1,7 +1,8 @@
1
- module Adsf
2
-
3
- VERSION = '1.2.1'
1
+ require 'rack'
4
2
 
3
+ module Adsf
5
4
  end
6
5
 
6
+ require 'adsf/version'
7
7
  require 'adsf/rack'
8
+ require 'adsf/server'
@@ -1,8 +1,6 @@
1
1
  module Adsf
2
-
3
2
  module Rack
4
3
  end
5
-
6
4
  end
7
5
 
8
6
  require 'adsf/rack/index_file_finder'
@@ -1,11 +1,9 @@
1
1
  module Adsf::Rack
2
-
3
2
  class IndexFileFinder
4
-
5
- def initialize(app, options)
3
+ def initialize(app, root:, index_filenames: ['index.html'])
6
4
  @app = app
7
- @root = options[:root] or raise ArgumentError, ':root option is required but was not given'
8
- @index_filenames = options[:index_filenames] || [ 'index.html' ]
5
+ @root = root
6
+ @index_filenames = index_filenames
9
7
  end
10
8
 
11
9
  def call(env)
@@ -14,19 +12,20 @@ module Adsf::Rack
14
12
  path = ::File.join(@root, path_info)
15
13
 
16
14
  # Redirect if necessary
17
- if ::File.directory?(path) && path_info !~ /\/$/
15
+ if ::File.directory?(path) && path_info !~ %r{/$}
18
16
  new_path_info = env['PATH_INFO'] + '/'
19
17
  return [
20
18
  302,
21
19
  { 'Location' => new_path_info, 'Content-Type' => 'text/html' },
22
- [ "Redirecting you to #{new_path_info}&hellip;" ]
20
+ ["Redirecting you to #{new_path_info}&hellip;"]
23
21
  ]
24
22
  end
25
23
 
26
24
  # Add index file if necessary
27
25
  new_env = env.dup
28
26
  if ::File.directory?(path)
29
- if index_filename = index_file_in(path)
27
+ index_filename = index_file_in(path)
28
+ if index_filename
30
29
  new_env['PATH_INFO'] = ::File.join(path_info, index_filename)
31
30
  end
32
31
  end
@@ -35,14 +34,12 @@ module Adsf::Rack
35
34
  @app.call(new_env)
36
35
  end
37
36
 
38
- private
37
+ private
39
38
 
40
39
  def index_file_in(dir)
41
40
  @index_filenames.find do |index_filename|
42
41
  ::File.file?(::File.join(dir, index_filename))
43
42
  end
44
43
  end
45
-
46
44
  end
47
-
48
45
  end
@@ -0,0 +1,68 @@
1
+ module Adsf
2
+ class Server
3
+ DEFAULT_HANDLER_NAME = :thin
4
+
5
+ def initialize(root:, index_filenames: ['index.html'], host: '127.0.0.1', port: 3000, handler: nil)
6
+ @root = root
7
+ @index_filenames = index_filenames
8
+ @host = host
9
+ @port = port
10
+ @handler = handler
11
+
12
+ @q = SizedQueue.new(1)
13
+ end
14
+
15
+ def run
16
+ handler = build_handler
17
+ app = build_app(root: @root, index_filenames: @index_filenames)
18
+
19
+ url = "http://#{@host}:#{@port}/"
20
+ puts "View the site at #{url}"
21
+
22
+ handler.run(app, Host: @host, Port: @port) do |server|
23
+ wait_for_stop_async(server)
24
+ end
25
+ end
26
+
27
+ def stop
28
+ @q << true
29
+ end
30
+
31
+ private
32
+
33
+ def wait_for_stop_async(server)
34
+ Thread.new { wait_for_stop(server) }
35
+ end
36
+
37
+ def wait_for_stop(server)
38
+ @q.pop
39
+ server.stop
40
+ end
41
+
42
+ def build_app(root:, index_filenames:)
43
+ ::Rack::Builder.new do
44
+ use ::Rack::CommonLogger
45
+ use ::Rack::ShowExceptions
46
+ use ::Rack::Lint
47
+ use ::Rack::Head
48
+ use Adsf::Rack::IndexFileFinder,
49
+ root: root,
50
+ index_filenames: index_filenames
51
+
52
+ run ::Rack::File.new(root)
53
+ end.to_app
54
+ end
55
+
56
+ def build_handler
57
+ if @handler
58
+ ::Rack::Handler.get(@handler)
59
+ else
60
+ begin
61
+ ::Rack::Handler.get(DEFAULT_HANDLER_NAME)
62
+ rescue LoadError
63
+ ::Rack::Handler::WEBrick
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Adsf
2
+ VERSION = '1.3.0'.freeze
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adsf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2017-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
27
33
  description: A web server that can be spawned in any directory
28
34
  email: denis.defreyne@stoneship.org
29
35
  executables:
@@ -42,6 +48,8 @@ files:
42
48
  - lib/adsf.rb
43
49
  - lib/adsf/rack.rb
44
50
  - lib/adsf/rack/index_file_finder.rb
51
+ - lib/adsf/server.rb
52
+ - lib/adsf/version.rb
45
53
  homepage: http://github.com/ddfreyne/adsf/
46
54
  licenses:
47
55
  - MIT
@@ -54,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
62
  requirements:
55
63
  - - ">="
56
64
  - !ruby/object:Gem::Version
57
- version: 1.8.5
65
+ version: 2.2.0
58
66
  required_rubygems_version: !ruby/object:Gem::Requirement
59
67
  requirements:
60
68
  - - ">="
@@ -62,9 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
70
  version: '0'
63
71
  requirements: []
64
72
  rubyforge_project:
65
- rubygems_version: 2.5.2
73
+ rubygems_version: 2.7.2
66
74
  signing_key:
67
75
  specification_version: 4
68
76
  summary: a tiny static file server
69
77
  test_files: []
70
- has_rdoc: false