servethis2 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in servethis2.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 MOZGIII
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # Servethis2
2
+
3
+ Expose a directory to the web with a single command.
4
+
5
+ ## Installation
6
+
7
+ $ gem install servethis2
8
+
9
+ ## Usage
10
+
11
+ servethis2
12
+
13
+ or
14
+
15
+ servethis2 . -p 8000
16
+
17
+ ## Contributing
18
+
19
+ 1. Fork it
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
22
+ 4. Push to the branch (`git push origin my-new-feature`)
23
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "servethis2"
3
+ Servethis2::CLI.run
@@ -0,0 +1,2 @@
1
+ require "servethis2/version"
2
+ require "servethis2/cli"
@@ -0,0 +1,41 @@
1
+ require "optparse"
2
+ require "servethis2/server"
3
+ require "servethis2/version"
4
+
5
+ module Servethis2
6
+ class CLI
7
+ def default_options
8
+ {
9
+ :Port => 8000,
10
+ :DocumentRoot => ".",
11
+ :ServerSoftware => "Servethis2/#{Servethis2::VERSION} " +
12
+ "(Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE})"
13
+ }
14
+ end
15
+
16
+ def options
17
+ @options ||= default_options
18
+ end
19
+
20
+ def optparse!
21
+ OptionParser.new do |opts|
22
+ opts.banner = "Usage: #{$0} [doc_root] [-p port]"
23
+
24
+ opts.on("-p", "--port PORT", "Use specified port") do |p|
25
+ options[:Port] = p
26
+ end
27
+ end.parse!
28
+
29
+ options[:DocumentRoot] = ARGV[0] if ARGV[0]
30
+ end
31
+
32
+ def run
33
+ optparse!
34
+ Server.new(options).start
35
+ end
36
+
37
+ def self.run
38
+ self.new.run
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require "rack"
2
+ require "rack/nocache"
3
+
4
+ module Servethis2
5
+ class Server
6
+ attr_reader :options
7
+
8
+ def initialize(options = {})
9
+ @options = options
10
+ prepare
11
+ end
12
+
13
+ def prepare
14
+ doc_root = options[:DocumentRoot].gsub(::File::ALT_SEPARATOR, ::File::SEPARATOR)
15
+ puts "Working with #{doc_root}"
16
+ puts "Warning! Path does not exist!" unless Dir.exists? doc_root
17
+
18
+ builder = Rack::Builder.new do
19
+ use Rack::CommonLogger
20
+ use Rack::ShowExceptions
21
+ use Rack::Nocache
22
+
23
+ run Rack::File.new(doc_root)
24
+ end
25
+
26
+ options[:app] = builder
27
+ end
28
+
29
+
30
+ def start
31
+ Rack::Server.start(options)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Servethis2
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'servethis2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "servethis2"
8
+ spec.version = Servethis2::VERSION
9
+ spec.authors = ["MOZGIII"]
10
+ spec.email = ["mike-n@narod.ru"]
11
+ spec.description = %q{This gem provides a command to run a web server inside a particulatr directory.}
12
+ spec.summary = %q{Explore a directory to the web with a single command!}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "rack"
24
+ spec.add_dependency "rack-nocache"
25
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: servethis2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - MOZGIII
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rack
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-nocache
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: This gem provides a command to run a web server inside a particulatr
79
+ directory.
80
+ email:
81
+ - mike-n@narod.ru
82
+ executables:
83
+ - servethis2
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/servethis2
93
+ - lib/servethis2.rb
94
+ - lib/servethis2/cli.rb
95
+ - lib/servethis2/server.rb
96
+ - lib/servethis2/version.rb
97
+ - servethis2.gemspec
98
+ homepage: ''
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.24
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Explore a directory to the web with a single command!
123
+ test_files: []
124
+ has_rdoc: