oxy 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/bin/oxy +5 -0
- data/lib/oxy/server.rb +115 -0
- data/lib/oxy/version.rb +1 -1
- data/lib/oxy.rb +1 -3
- data/oxy.gemspec +11 -2
- metadata +120 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3a23994e0098c5d49df8b240845baa9340739e1
|
|
4
|
+
data.tar.gz: 0c2adf420f29e5d316ee2590005518d193532b51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03f74bad6f4c45d79fd5a106aef3c72a5c3a33ddeafcf5a2091bf962d8e40e5182112eb0a69dc6fcaec0c77f9ce6c0193e415b1bd74da8681b01e0f0d8addae4
|
|
7
|
+
data.tar.gz: 9f975637fc3477b4a6c3aa23824a7fdbcfd80010196481126d793c4f4bf95634040f21511911d189875116c87b593c30200eda8bab37cd339970f0e6ec087ea6
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/oxy
ADDED
data/lib/oxy/server.rb
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require "optparse"
|
|
2
|
+
require "ostruct"
|
|
3
|
+
require "rack"
|
|
4
|
+
require "rack/contrib"
|
|
5
|
+
|
|
6
|
+
module Oxy
|
|
7
|
+
class Server
|
|
8
|
+
attr_accessor :options
|
|
9
|
+
|
|
10
|
+
attr_reader :stdout
|
|
11
|
+
|
|
12
|
+
def initialize(argv = [], stdin = $stdin, stdout = $stdout, stderr = $stderr)
|
|
13
|
+
@stdout = stdout
|
|
14
|
+
@options = OpenStruct.new
|
|
15
|
+
@parser = option_parser
|
|
16
|
+
# actually parse arguments input
|
|
17
|
+
parse_options(argv)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def run
|
|
21
|
+
# setup oxy's folder
|
|
22
|
+
FileUtils.mkdir_p(oxy_home_path) unless File.exist?(oxy_home_path)
|
|
23
|
+
# process user's options (if any)
|
|
24
|
+
miscellaneous
|
|
25
|
+
# start server's thread
|
|
26
|
+
server_thread = start_server
|
|
27
|
+
# wait for the server's thread to join
|
|
28
|
+
server_thread.join if server_thread
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
def oxy_home_path
|
|
33
|
+
"#{ENV["HOME"]}/oxy"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def static_site_app
|
|
37
|
+
# pin site_root_path
|
|
38
|
+
site_root_path = @options.document_root
|
|
39
|
+
# pin not_found_path file path
|
|
40
|
+
not_found_path = File.join(site_root_path, "404.html")
|
|
41
|
+
# build new app
|
|
42
|
+
stack = Rack::Builder.new {
|
|
43
|
+
use Rack::CommonLogger
|
|
44
|
+
use Rack::TryStatic, :urls => %w[/], :try => ['.html', 'index.html', '/index.html']
|
|
45
|
+
run Rack::NotFound.new(not_found_path)
|
|
46
|
+
}
|
|
47
|
+
return stack.to_app
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def start_server
|
|
51
|
+
# instantiate our Rack server
|
|
52
|
+
@server = Rack::Server.new({
|
|
53
|
+
:app => static_site_app,
|
|
54
|
+
:pid => File.join(oxy_home_path,"oxy.pid"),
|
|
55
|
+
:Port => @options.port,
|
|
56
|
+
:Host => @options.address,
|
|
57
|
+
:environment => 'deployment',
|
|
58
|
+
:server => 'puma',
|
|
59
|
+
:daemonize => false
|
|
60
|
+
})
|
|
61
|
+
# spin the server
|
|
62
|
+
Thread.new { @server.start }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def parse_options(argv = [])
|
|
66
|
+
begin
|
|
67
|
+
# parse options input from the user
|
|
68
|
+
@parser.parse!(argv)
|
|
69
|
+
# set option defaults
|
|
70
|
+
@options.document_root = Dir.pwd unless @options.document_root
|
|
71
|
+
@options.port = 4000 unless @options.port
|
|
72
|
+
rescue OptionParser::ParseError => pe
|
|
73
|
+
msg = ["#{@parser.program_name}: #{pe}", "Try `#{@parser.program_name} --help` for more information"]
|
|
74
|
+
@options.error_message = msg.join("\n")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Miscellaneous options simply renders the appropriate information to the output.
|
|
79
|
+
def miscellaneous
|
|
80
|
+
if @options.show_version then
|
|
81
|
+
@stdout.puts "#{@parser.program_name}: version #{Oxy::VERSION}"
|
|
82
|
+
exit 0
|
|
83
|
+
elsif @options.show_help then
|
|
84
|
+
@stdout.puts @parser.to_s
|
|
85
|
+
exit 0
|
|
86
|
+
elsif @options.error_message then
|
|
87
|
+
@stdout.puts @options.error_message
|
|
88
|
+
exit 1
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def option_parser
|
|
93
|
+
# We derive our options from Puma to avoid confusion
|
|
94
|
+
OptionParser.new do |op|
|
|
95
|
+
op.separator ""
|
|
96
|
+
# parse help
|
|
97
|
+
op.on("-h", "--help", "Display this text") do
|
|
98
|
+
@options.show_help = true
|
|
99
|
+
end
|
|
100
|
+
# parse version
|
|
101
|
+
op.on("-V", "--version", "Show version") do
|
|
102
|
+
@options.show_version = true
|
|
103
|
+
end
|
|
104
|
+
# parse uri
|
|
105
|
+
op.on("-b", "--bind URI", "URI to bind to (tcp://, unix://, ssl://)") do |uri|
|
|
106
|
+
@options.uri = uri
|
|
107
|
+
end
|
|
108
|
+
# parse port no.
|
|
109
|
+
op.on("-p", "--port PORT", Integer, "Define the TCP port to bind to", "Use -b for more advanced options") do |port|
|
|
110
|
+
@options.port = port
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
data/lib/oxy/version.rb
CHANGED
data/lib/oxy.rb
CHANGED
data/oxy.gemspec
CHANGED
|
@@ -16,11 +16,20 @@ Gem::Specification.new do |spec|
|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
17
|
f.match(%r{^(test|spec|features)/})
|
|
18
18
|
end
|
|
19
|
-
spec.
|
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
19
|
+
spec.executables = ["oxy".freeze]
|
|
21
20
|
spec.require_paths = ["lib"]
|
|
22
21
|
|
|
22
|
+
spec.add_runtime_dependency "rack", "~> 2.0"
|
|
23
|
+
spec.add_runtime_dependency "rack-contrib", "~> 1.2"
|
|
24
|
+
spec.add_runtime_dependency "puma", "~> 3.10"
|
|
25
|
+
|
|
23
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
|
24
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "pry"
|
|
31
|
+
spec.add_development_dependency "pry-byebug"
|
|
32
|
+
spec.add_development_dependency "pry-doc"
|
|
33
|
+
spec.add_development_dependency "pry-rescue"
|
|
34
|
+
spec.add_development_dependency "pry-stack_explorer"
|
|
26
35
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oxy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pavel Tsurbeleu
|
|
8
8
|
autorequire:
|
|
9
|
-
bindir:
|
|
9
|
+
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-10-
|
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rack
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rack-contrib
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.2'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.2'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: puma
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.10'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.10'
|
|
13
55
|
- !ruby/object:Gem::Dependency
|
|
14
56
|
name: bundler
|
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,10 +94,81 @@ dependencies:
|
|
|
52
94
|
- - "~>"
|
|
53
95
|
- !ruby/object:Gem::Version
|
|
54
96
|
version: '5.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: pry
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: pry-byebug
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: pry-doc
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: pry-rescue
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: pry-stack_explorer
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0'
|
|
55
167
|
description:
|
|
56
168
|
email:
|
|
57
169
|
- pavel.tsurbeleu@me.com
|
|
58
|
-
executables:
|
|
170
|
+
executables:
|
|
171
|
+
- oxy
|
|
59
172
|
extensions: []
|
|
60
173
|
extra_rdoc_files: []
|
|
61
174
|
files:
|
|
@@ -67,8 +180,10 @@ files:
|
|
|
67
180
|
- README.md
|
|
68
181
|
- Rakefile
|
|
69
182
|
- bin/console
|
|
183
|
+
- bin/oxy
|
|
70
184
|
- bin/setup
|
|
71
185
|
- lib/oxy.rb
|
|
186
|
+
- lib/oxy/server.rb
|
|
72
187
|
- lib/oxy/version.rb
|
|
73
188
|
- oxy.gemspec
|
|
74
189
|
homepage: http://oxy.io
|
|
@@ -91,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
91
206
|
version: '0'
|
|
92
207
|
requirements: []
|
|
93
208
|
rubyforge_project:
|
|
94
|
-
rubygems_version: 2.6.
|
|
209
|
+
rubygems_version: 2.6.10
|
|
95
210
|
signing_key:
|
|
96
211
|
specification_version: 4
|
|
97
212
|
summary: Oxy is a web server for static sites
|