miron 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cb072267bfc059dd87476db6a6beeef482d146b
4
- data.tar.gz: 88d977829876a1ac2c3065b6c077a3dfc5d3cea6
3
+ metadata.gz: 6262a9abd0913ef9667e4b30daae12d97c12bfaa
4
+ data.tar.gz: 7026a6635931843ca5b6b70c2e8c2114e71a3407
5
5
  SHA512:
6
- metadata.gz: 6bcf690d497f18ed1a5c5ea21a934150c09d0e07ae6ef0d63fe05bde31204bb672ce8408a0b9d4037777a62cbdfe148646c04391dfef85441e8ec738c9959129
7
- data.tar.gz: b73d71624ae079a8fa61d1ca5f3e842dd7a0451b0405b077b37469d9dda83428a0b04ba88d84f34ef1994a81d5e599561e140b538c3d2408f32bb92363ada9f3
6
+ metadata.gz: 509fad0561f9b1cea4acfdd35643144fd3df15b1387dac73fc4b5641a79c48341ba8c2a3e11cffcbd4f056786eaf5d400d97b81efff6886ea569c26a0685ac1e
7
+ data.tar.gz: 5ad54af7fefb29ce74e141f2191db64113d7a6d3b5c3e85a63eb38da6078cce94ef4eeb67c982c352efc8a04e8788a7eea640208e59a149ce10c7955d1912a8d
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Moss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mimemagic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: multi_json
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -194,45 +208,10 @@ dependencies:
194
208
  version: '0'
195
209
  description: A redesigned Ruby web interface.
196
210
  email: me@jonathanmoss.me
197
- executables:
198
- - miron
211
+ executables: []
199
212
  extensions: []
200
213
  extra_rdoc_files: []
201
- files:
202
- - ".gitignore"
203
- - ".rspec"
204
- - ".rubocop.yml"
205
- - ".rubocop_todo.yml"
206
- - ".travis.yml"
207
- - ".yardopts"
208
- - CHANGELOG.md
209
- - CONTRIBUTING.md
210
- - Gemfile
211
- - LICENSE.md
212
- - README.md
213
- - Rakefile
214
- - UPGRADING.md
215
- - bin/console
216
- - bin/setup
217
- - bin/travis
218
- - exe/miron
219
- - lib/miron.rb
220
- - lib/miron/auth/basic.rb
221
- - lib/miron/command.rb
222
- - lib/miron/command/init.rb
223
- - lib/miron/command/server.rb
224
- - lib/miron/handler.rb
225
- - lib/miron/handlers/puma.rb
226
- - lib/miron/handlers/thin.rb
227
- - lib/miron/handlers/unicorn.rb
228
- - lib/miron/handlers/webrick.rb
229
- - lib/miron/mironfile.rb
230
- - lib/miron/request.rb
231
- - lib/miron/response.rb
232
- - lib/miron/server.rb
233
- - lib/miron/utils.rb
234
- - lib/miron/version.rb
235
- - miron.gemspec
214
+ files: []
236
215
  homepage: https://github.com/mironrb/miron
237
216
  licenses:
238
217
  - MIT
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /rack_stuff
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,6 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - rack_stuff/**/*
4
- - tmp/**/*
5
-
6
- inherit_from: .rubocop_todo.yml
@@ -1,12 +0,0 @@
1
- Lint/Eval:
2
- Enabled: false
3
- Metrics/AbcSize:
4
- Enabled: false
5
- Metrics/LineLength:
6
- Max: 120
7
- Metrics/MethodLength:
8
- Max: 15
9
- Style/BracesAroundHashParameters:
10
- Enabled: false
11
- Style/Documentation:
12
- Enabled: false
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2
4
- before_install: gem install bundler -v 1.10.6
5
- before_script: bin/travis
data/.yardopts DELETED
@@ -1,3 +0,0 @@
1
- --markup markdown
2
- --exclude bin
3
- --exclude spec
@@ -1,10 +0,0 @@
1
- ### 0.0.2 - Next Release
2
- * Add `Miron::Auth::Basic` middleware to allow HTTP Basic authentication - [@maclover7](https://github.com/maclover7).
3
- * Add `use` to Mironfile.rb to allow adding of middleware - [@maclover7](https://github.com/maclover7).
4
- * Add Puma HTTP handler - [@maclover7](https://github.com/maclover7).
5
- * Add Unicorn HTTP handler - [@maclover7](https://github.com/maclover7).
6
- * Add Thin HTTP handler - [@maclover7](https://github.com/maclover7).
7
-
8
- ### 0.0.1 (9/21/2015)
9
- * Initial public release - [@maclover7](https://github.com/maclover7).
10
- * Add WEBrick HTTP Handler - [@maclover7](https://github.com/maclover7).
@@ -1,125 +0,0 @@
1
- # Contributing to Miron
2
-
3
- This project is work of [many contributors](https://github.com/mironrb/miron/graphs/contributors).
4
-
5
- You're encouraged to submit [pull requests](https://github.com/mironrb/miron/pulls), [propose features and discuss issues](https://github.com/mironrb/miron/issues).
6
-
7
- In the examples below, substitute your Github username for `contributor` in URLs.
8
-
9
- ## Fork the Project
10
-
11
- Fork the [project on Github](https://github.com/mironrb/miron) and check out your copy.
12
-
13
- ```
14
- git clone https://github.com/contributor/miron.git
15
- cd miron
16
- git remote add upstream https://github.com/mironrb/miron.git
17
- ```
18
-
19
- ## Bundle Install and Test
20
-
21
- Ensure that you can build the project and run tests.
22
-
23
- ```
24
- bundle install
25
- bundle exec rake
26
- ```
27
-
28
- ## Create a Topic Branch
29
-
30
- Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
31
-
32
- ```
33
- git checkout master
34
- git pull upstream master
35
- git checkout -b my-feature-branch
36
- ```
37
-
38
- ## Write Tests
39
-
40
- Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
41
- Add to [spec](spec).
42
-
43
- We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
44
-
45
- ## Write Code
46
-
47
- Implement your feature or bug fix.
48
-
49
- Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
50
- Run `bundle exec rubocop` and fix any style issues highlighted.
51
-
52
- Make sure that `bundle exec rake` completes without errors.
53
-
54
- ## Write Documentation
55
-
56
- Document any external behavior in the [README](README.md).
57
-
58
- ## Update Changelog
59
-
60
- Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
61
- Make it look like every other line, including your name and link to your Github account.
62
-
63
- ## Commit Changes
64
-
65
- Make sure git knows your name and email address:
66
-
67
- ```
68
- git config --global user.name "Your Name"
69
- git config --global user.email "contributor@example.com"
70
- ```
71
-
72
- Writing good commit logs is important. A commit log should describe what changed and why.
73
-
74
- ```
75
- git add ...
76
- git commit
77
- ```
78
-
79
- ## Push
80
-
81
- ```
82
- git push origin my-feature-branch
83
- ```
84
-
85
- ## Make a Pull Request
86
-
87
- Go to https://github.com/contributor/miron and select your feature branch.
88
- Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
89
-
90
- ## Rebase
91
-
92
- If you've been working on a change for a while, rebase with upstream/master.
93
-
94
- ```
95
- git fetch upstream
96
- git rebase upstream/master
97
- git push origin my-feature-branch -f
98
- ```
99
-
100
- ## Update CHANGELOG Again
101
-
102
- Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
103
-
104
- ```
105
- * [#123](https://github.com/mironrb/miron/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
106
- ```
107
-
108
- Amend your previous commit and force push the changes.
109
-
110
- ```
111
- git commit --amend
112
- git push origin my-feature-branch -f
113
- ```
114
-
115
- ## Check on Your Pull Request
116
-
117
- Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
118
-
119
- ## Be Patient
120
-
121
- It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
122
-
123
- ## Thank You
124
-
125
- Please do know that we really appreciate and value your time and work. We love you, really.
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in miron.gemspec
4
- gemspec
data/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) 2015 Jon Moss and Contributors
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.
data/README.md DELETED
@@ -1,19 +0,0 @@
1
- # Miron
2
-
3
- [![Build Status](https://travis-ci.org/mironrb/miron.svg)](https://travis-ci.org/mironrb/miron)
4
-
5
- A redesigned Ruby web interface.
6
-
7
- ## Contributing
8
-
9
- See [CONTRIBUTING](CONTRIBUTING.md).
10
-
11
- ## Upgrading
12
-
13
- See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
14
-
15
- ## Copyright and License
16
-
17
- Copyright (c) 2015, [Jon Moss](https://twitter.com/applerebel), and [Contributors](CHANGELOG.md).
18
-
19
- This project is licensed under the [MIT License](LICENSE.md).
data/Rakefile DELETED
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'bundler/gem_tasks'
4
-
5
- Bundler.setup :default, :development
6
-
7
- require 'rspec/core'
8
- require 'rspec/core/rake_task'
9
-
10
- RSpec::Core::RakeTask.new(:spec) do |spec|
11
- spec.pattern = FileList['spec/**/*_spec.rb']
12
- end
13
-
14
- require 'rubocop/rake_task'
15
- RuboCop::RakeTask.new
16
-
17
- task default: [:rubocop, :spec]
@@ -1,4 +0,0 @@
1
- Upgrading Miron
2
- ======================
3
-
4
- ### Coming Soon
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'miron'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
data/bin/travis DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pathname'
4
-
5
- Dir.mkdir('tmp') unless Dir.exist?(Pathname.pwd + 'tmp')
6
-
7
- puts 'tmp was/has been created'
data/exe/miron DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'miron'
5
-
6
- Miron::Command.run(ARGV)
@@ -1,29 +0,0 @@
1
- require 'pathname'
2
- require 'active_support/core_ext/string/strip'
3
- require 'active_support/core_ext/string/inflections'
4
- require 'multi_json'
5
-
6
- require 'miron/version'
7
-
8
- # Miron: The Gem, The Myth, The Legend
9
- #
10
- module Miron
11
- autoload :Command, 'miron/command'
12
- autoload :Handler, 'miron/handler'
13
- autoload :Mironfile, 'miron/mironfile'
14
- autoload :Response, 'miron/response'
15
- autoload :Request, 'miron/request'
16
- autoload :Server, 'miron/server'
17
- autoload :Utils, 'miron/utils'
18
-
19
- module Auth
20
- autoload :Basic, 'miron/auth/basic'
21
- end
22
-
23
- class Handler
24
- autoload :Puma, 'miron/handlers/puma'
25
- autoload :Thin, 'miron/handlers/thin'
26
- autoload :Unicorn, 'miron/handlers/unicorn'
27
- autoload :WEBrick, 'miron/handlers/webrick'
28
- end
29
- end
@@ -1,50 +0,0 @@
1
- module Miron
2
- module Auth
3
- class Basic
4
- attr_reader :request
5
-
6
- def self.call(request)
7
- @request = request
8
- return unauthorized if authorization_key.nil?
9
- check_auth
10
- end
11
-
12
- def self.auth_cleared
13
- true
14
- end
15
-
16
- def self.authorization_key
17
- authorization_keys = ['HTTP_AUTHORIZATION', 'HTTP_X-HTTP_AUTHORIZATION', 'HTTP_X_HTTP_AUTHORIZATION']
18
- @authorization_key ||= authorization_keys.detect { |key| @request.key?(key) } || nil
19
- end
20
-
21
- def self.bad_request
22
- Miron::Response.new(400, { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }, '')
23
- end
24
-
25
- def self.check_auth
26
- # Get Auth Scheme and encoded username/password
27
- auth_key = @request[authorization_key].split(' ', 2)
28
- scheme = auth_key.first && auth_key.first.downcase
29
- return bad_request if scheme != 'basic'
30
-
31
- # Validate credentials
32
- decrypted_auth_key = auth_key.last.unpack('m*').first.split(/:/, 2)
33
- if [ENV['MIRON_BAUTH_USERNAME'], ENV['MIRON_BAUTH_PWD']] == decrypted_auth_key
34
- return auth_cleared
35
- else
36
- return unauthorized
37
- end
38
- end
39
-
40
- def self.unauthorized
41
- Miron::Response.new(401,
42
- { 'Content-Type' => 'text/plain',
43
- 'Content-Length' => '0',
44
- 'WWW-Authenticate' => 'Basic realm="Login"'
45
- },
46
- '')
47
- end
48
- end
49
- end
50
- end
@@ -1,28 +0,0 @@
1
- require 'claide'
2
-
3
- module Miron
4
- class Command < CLAide::Command
5
- require 'miron/command/init'
6
- require 'miron/command/server'
7
-
8
- self.abstract_command = true
9
- self.command = 'miron'
10
- self.version = VERSION
11
- self.description = 'Miron, a redesigned Ruby web interface.'
12
- self.plugin_prefixes = %w(claide miron)
13
-
14
- def self.options
15
- [
16
- ].concat(super)
17
- end
18
-
19
- def self.run(argv)
20
- help! 'You cannot run Miron as root.' if Process.uid == 0
21
- super(argv)
22
- end
23
-
24
- def initialize(argv)
25
- super
26
- end
27
- end
28
- end
@@ -1,37 +0,0 @@
1
- module Miron
2
- class Command
3
- class Init < Command
4
- self.summary = 'Generate a Mironfile for the current directory.'
5
- self.description = 'Creates a Mironfile for the current directory if none currently exists.'
6
- self.arguments = [
7
- ]
8
-
9
- def initialize(argv)
10
- @mironfile_path = Pathname.pwd + 'Mironfile.rb'
11
- super
12
- end
13
-
14
- def validate!
15
- super
16
- help! 'Existing Mironfile found in directory' if Miron::Utils.mironfile_in_dir(Pathname.pwd)
17
- end
18
-
19
- def run
20
- @mironfile_path.open('w') { |f| f << mironfile_template }
21
- end
22
-
23
- private
24
-
25
- # @return [String] the text of the Podfile for the provided project
26
- #
27
- def mironfile_template
28
- mironfile = ''
29
- mironfile << <<-MIRON.strip_heredoc
30
- # This file is used by Miron-based servers to start the application.
31
- MIRON
32
-
33
- mironfile << "\n"
34
- end
35
- end
36
- end
37
- end
@@ -1,34 +0,0 @@
1
- module Miron
2
- class Command
3
- class Server < Command
4
- self.summary = 'Start a Miron-backed server.'
5
- self.description = 'Start a Miron-backed server.'
6
-
7
- def self.options
8
- [
9
- ['--port=PORT', 'Port to run the Mironfile on'],
10
- ['--handler=HANDLER', 'Handler to use for your Miron-backed server']
11
- ].concat(super)
12
- end
13
-
14
- def initialize(argv)
15
- @mironfile = Miron::Mironfile.from_dir(Pathname.pwd)
16
- @options = {}
17
- @options['port'] = argv.option('port') || 9290
18
- @options['handler'] = argv.option('handler')
19
- @options['mironfile_path'] = Pathname.pwd + 'Mironfile'
20
- super
21
- end
22
-
23
- def validate!
24
- super
25
- help! 'No Mironfile found in directory' if Miron::Utils.mironfile_in_dir(Pathname.pwd) == false
26
- end
27
-
28
- def run
29
- server = Miron::Server.new(@mironfile, @options)
30
- server.start
31
- end
32
- end
33
- end
34
- end
@@ -1,21 +0,0 @@
1
- module Miron
2
- class Handler
3
- # @param [String] handler_name
4
- # inheritor of {Miron::Handler} to try and use to run a Miron-backed server
5
- #
6
- # @return [Miron::Handler]
7
- # returns constant of handler_name, if it can be found
8
- #
9
- # @return [Miron::Handler]
10
- # returns the newly created {Miron::Response}
11
- # returns constant of {Miron::Handle::WEBrick}, if handler_name cannot be found
12
- #
13
- def self.get(handler_name)
14
- if !handler_name.nil? && Miron::Handler.const_defined?(:"#{handler_name.capitalize}")
15
- Miron::Handler.const_get(:"#{handler_name.capitalize}")
16
- else
17
- Miron::Handler::WEBrick
18
- end
19
- end
20
- end
21
- end
@@ -1,55 +0,0 @@
1
- require 'puma'
2
-
3
- module Miron
4
- class Handler
5
- class Puma
6
- def self.run(mironfile, options = {})
7
- Puma::Proxy.new(mironfile, options)
8
- end
9
-
10
- def initialize(mironfile)
11
- @mironfile = mironfile
12
- end
13
-
14
- def call(env)
15
- # Get response
16
- miron_request = env
17
- miron_response = Miron::Request.new(miron_request, @mironfile).fetch_response
18
- # Process response
19
- response_http_status = miron_response.http_status
20
- # Add cookies to headers
21
- miron_response.cookies.each do |k, v|
22
- miron_response.headers['Set-Cookie'] = "#{k}=#{v}"
23
- end
24
- response_body = [miron_response.body]
25
- [response_http_status, miron_response.headers, response_body]
26
- end
27
-
28
- class Proxy
29
- def initialize(mironfile, options)
30
- @mironfile = mironfile
31
- @options = options
32
- @serv = ::Puma::Server.new(Puma.new(@mironfile))
33
- listen(@options['host'], @options['port'].to_i)
34
- end
35
-
36
- def stop
37
- @serv.stop
38
- end
39
-
40
- def listen(address, port)
41
- @serv.add_tcp_listener(address, port)
42
- @serv.run
43
- puts "Puma #{::Puma::Const::PUMA_VERSION} starting..."
44
- puts "* Environment: #{@options['environment']}"
45
- puts "* Listening on #{@options['host']}:#{@options['port']}"
46
- begin
47
- sleep
48
- rescue Interrupt
49
- puts '* Shutting down...'
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,53 +0,0 @@
1
- require 'thin'
2
-
3
- module Miron
4
- class Handler
5
- class Thin < Thin::Server
6
- def self.run(mironfile, options = {})
7
- Thin::Proxy.new(mironfile, options)
8
- end
9
-
10
- def initialize(mironfile, *args)
11
- @mironfile = mironfile
12
- super
13
- end
14
-
15
- def call(env)
16
- # Get response
17
- miron_request = env
18
- miron_response = Miron::Request.new(miron_request, @mironfile).fetch_response
19
- # Process response
20
- response_http_status = miron_response.http_status
21
- # Add cookies to headers
22
- miron_response.cookies.each do |k, v|
23
- miron_response.headers['Set-Cookie'] = "#{k}=#{v}"
24
- end
25
- response_body = [miron_response.body]
26
- # Write back to Unicorn
27
- [response_http_status, miron_response.headers, response_body]
28
- end
29
-
30
- def start
31
- @app = self
32
- super
33
- end
34
-
35
- class Proxy
36
- def initialize(mironfile, options)
37
- @mironfile = mironfile
38
- @options = options
39
- listen(@options['host'], @options['port'].to_i)
40
- end
41
-
42
- def listen(address, port)
43
- args = [address, port, nil]
44
- # Thin versions below 0.8.0 do not support additional options
45
- args.pop if ::Thin::VERSION::MAJOR < 1 && ::Thin::VERSION::MINOR < 8
46
- server = ::Miron::Handler::Thin.new(@mironfile, *args)
47
- yield server if block_given?
48
- server.start
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,59 +0,0 @@
1
- require 'unicorn'
2
-
3
- module Miron
4
- class Handler
5
- class Unicorn < Unicorn::HttpServer
6
- def self.run(mironfile, options = {})
7
- Unicorn::Proxy.new(mironfile, options)
8
- end
9
-
10
- def initialize(mironfile, options)
11
- @mironfile = mironfile
12
- super
13
- end
14
-
15
- def process_client(socket)
16
- # Get response
17
- miron_request = @request.read(socket)
18
- miron_response = Miron::Request.new(miron_request, @mironfile).fetch_response
19
- # Process response
20
- response_http_status = miron_response.http_status
21
- # Add cookies to headers
22
- miron_response.cookies.each do |k, v|
23
- miron_response.headers['Set-Cookie'] = "#{k}=#{v}"
24
- end
25
- response_body = [miron_response.body]
26
- # Write back to Unicorn
27
- http_response_write(socket, response_http_status, miron_response.headers, response_body)
28
- unless socket.closed?
29
- socket.shutdown
30
- socket.close
31
- end
32
- rescue => e
33
- handle_error(socket, e)
34
- end
35
-
36
- class Proxy
37
- def initialize(mironfile, options)
38
- @mironfile = mironfile
39
- @options = options
40
- listen(@options['host'], @options['port'].to_i)
41
- end
42
-
43
- def listen(address, port)
44
- puts 'Unicorn starting...'
45
- puts "* Environment: #{@options['environment']}"
46
- puts "* Listening on #{@options['host']}:#{@options['port']}"
47
- begin
48
- ::Miron::Handler::Unicorn.new(@mironfile, {
49
- listeners: ["#{address}:#{port}"],
50
- logger: Logger.new(nil)
51
- }).start.join
52
- rescue Interrupt
53
- puts '* Shutting down...'
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,52 +0,0 @@
1
- require 'webrick'
2
- require 'logger'
3
- require 'stringio'
4
-
5
- module Miron
6
- class Handler
7
- class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet
8
- def self.run(mironfile, options = {})
9
- options[:BindAddress] = options['host']
10
- options[:Port] = options['port']
11
- @server = ::WEBrick::HTTPServer.new(options)
12
- @server.mount('/', Miron::Handler::WEBrick, mironfile)
13
- yield @server if block_given?
14
-
15
- begin
16
- @server.start
17
- rescue Interrupt
18
- puts '* Shutting down...'
19
- end
20
- end
21
-
22
- def initialize(server, mironfile)
23
- super server
24
- @mironfile = mironfile
25
- end
26
-
27
- def service(webrick_request, webrick_response)
28
- miron_request = webrick_request.meta_vars
29
- parse_input_body(webrick_request, miron_request)
30
- miron_response = Miron::Request.new(miron_request, @mironfile).fetch_response
31
-
32
- webrick_response.status = miron_response.http_status
33
- webrick_response.body << miron_response.body
34
- miron_response.headers.each { |k, v| webrick_response[k] = v }
35
- miron_response.cookies.each { |k, v| webrick_response.cookies << "#{k}=#{v}" }
36
- miron_response.body.close if miron_response.body.respond_to?(:close)
37
- end
38
-
39
- def parse_input_body(webrick_request, miron_request)
40
- if webrick_request.body.to_s.nil? || webrick_request.body.to_s.empty?
41
- miron_request['HTTP_BODY'] = ''
42
- else
43
- miron_request['HTTP_BODY'] = ::MultiJson.load(webrick_request.body.to_s)
44
- end
45
- end
46
-
47
- def shutdown
48
- @server.shutdown
49
- end
50
- end
51
- end
52
- end
@@ -1,71 +0,0 @@
1
- module Miron
2
- class Mironfile
3
- # Returns the contents of the Mironfile in the given dir, if any exists.
4
- #
5
- # @param [Pathname] dir
6
- # The directory where to look for the Mironfile.
7
- #
8
- # @return [Miron::Mironfile] Returns newly create {Miron::Mironfile}
9
- # @return [Nil] If no Mironfile was found in the given dir
10
- #
11
- attr_reader :app, :middleware
12
-
13
- def self.from_dir(dir)
14
- path = dir + 'Mironfile.rb'
15
- mironfile = Mironfile.new(path) do
16
- eval(path.read, nil, path.to_s)
17
- end
18
- mironfile
19
- end
20
-
21
- def initialize(mironfile_path, &block)
22
- require_relative File.expand_path(mironfile_path, __FILE__)
23
- @middleware = []
24
- instance_eval(&block)
25
- end
26
-
27
- # Takes an argument that is an object that responds to #call and returns a {Miron::Response}.
28
- #
29
- # class Heartbeat
30
- # def self.call(request)
31
- # Miron::Response.new(200, { "Content-Type" => "text/plain" }, "OK")
32
- # end
33
- # end
34
- #
35
- # run Heartbeat
36
- def run(app)
37
- @app = app.to_s.gsub!('Miron::Mironfile::', '').constantize
38
- end
39
-
40
- # Takes an argument that is an object that responds to #call and returns a {Miron::Response}.
41
- #
42
- # class Middle
43
- # def self.call(request)
44
- # puts "hello from middle"
45
- # end
46
- # end
47
- #
48
- # class Heartbeat
49
- # def self.call(request)
50
- # Miron::Response.new(200, { "Content-Type" => "text/plain" }, "OK")
51
- # end
52
- # end
53
- #
54
- # use Middle
55
- # run Heartbeat
56
- def use(middleware)
57
- middleware_string = middleware.to_s
58
- if middleware_string.include?('Miron::Mironfile::')
59
- @middleware << middleware_string.gsub!('Miron::Mironfile::', '').constantize
60
- else
61
- @middleware << middleware_string.constantize
62
- end
63
- end
64
- end
65
- end
66
-
67
- def run(_)
68
- end
69
-
70
- def use(_)
71
- end
@@ -1,51 +0,0 @@
1
- module Miron
2
- # Miron::Request allows HTTP responses to be sent.
3
- #
4
- class Request
5
- attr_reader :request, :mironfile
6
-
7
- # @param [Hash] request
8
- # Request information
9
- #
10
- # @param [Mironfile] mironfile
11
- # Mironfile that has the app and middleware to perform a `.call` on
12
- #
13
- def initialize(request, mironfile)
14
- @request = request
15
- @mironfile = mironfile
16
- @response = Miron::Response.new
17
- fix_hash_keys
18
- end
19
-
20
- # @return [Response] returns the newly created {Miron::Response}
21
- #
22
- def fetch_response
23
- miron_response = nil
24
- @mironfile.middleware.each do |middleware|
25
- middleware_response = middleware.call(@request, @response)
26
- miron_response = middleware_response if middleware_response.is_a?(Miron::Response)
27
- end
28
-
29
- return miron_response unless miron_response.nil?
30
-
31
- app_response = @mironfile.app.call(@request, @response)
32
- miron_response = app_response if app_response.is_a?(Miron::Response)
33
- miron_response
34
- end
35
-
36
- private
37
-
38
- # Make request hash keys easier to understand.
39
- def fix_hash_keys
40
- # Convert PATH_INFO to PATH
41
- return unless @request['PATH_INFO']
42
- @request['PATH'] = @request['PATH_INFO']
43
- @request.delete('PATH_INFO')
44
-
45
- # Convert REQUEST_METHOD to HTTP_METHOD
46
- return unless @request['REQUEST_METHOD']
47
- @request['HTTP_METHOD'] = @request['REQUEST_METHOD']
48
- @request.delete('REQUEST_METHOD')
49
- end
50
- end
51
- end
@@ -1,25 +0,0 @@
1
- module Miron
2
- # Miron::Reponse allows HTTP responses to be sent.
3
- #
4
- class Response
5
- attr_accessor :http_status, :headers, :body, :cookies
6
-
7
- # @param [Integer] http_status
8
- # the HTTP status code to return
9
- #
10
- # @param [Hash] headers
11
- # the HTTP headers to return
12
- #
13
- # @param [String] body
14
- # the HTTP body to return
15
- #
16
- # @return [Response] returns the newly created {Miron::Response}
17
- #
18
- def initialize
19
- @http_status = 200
20
- @headers = {}
21
- @body = ''
22
- @cookies = {}
23
- end
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- module Miron
2
- # Miron::Server allows HTTP responses to be sent.
3
- #
4
- class Server
5
- attr_reader :mironfile, :options
6
- attr_accessor :handler
7
-
8
- # @param [Mironfile] mironfile
9
- # An instance of {Miron::Mironfile} that will be powering the {Miron::Server}
10
- #
11
- # @param [Hash] options
12
- # A Hash of configuration options
13
- #
14
- # @return [Response] returns the newly created {Miron::Server}
15
- #
16
- def initialize(mironfile, options)
17
- @mironfile = mironfile
18
- @options = options
19
- resolve_handler
20
- end
21
-
22
- def start
23
- # Set options defaults and run the handler
24
- @options['environment'] = ENV['MIRON_ENV'] || 'development'
25
- @options['host'] = '0.0.0.0'
26
- @handler.run(@mironfile, @options)
27
- end
28
-
29
- private
30
-
31
- def resolve_handler
32
- @handler = Miron::Handler.get(@options['handler'])
33
- end
34
- end
35
- end
@@ -1,20 +0,0 @@
1
- module Miron
2
- class Utils
3
- # Returns the path of the Mironfile in the given dir, if any exists.
4
- #
5
- # @param [Pathname] dir
6
- # The directory where to look for the Mironfile.
7
- #
8
- # @return [Pathname] The path of the Mironfile.
9
- # @return [Nil] If no Mironfile was found in the given dir
10
- #
11
- def self.mironfile_in_dir(dir)
12
- mironfile = dir + 'Mironfile.rb'
13
- if mironfile.exist?
14
- true
15
- else
16
- false
17
- end
18
- end
19
- end
20
- end
@@ -1,5 +0,0 @@
1
- module Miron
2
- # The version of Miron
3
- #
4
- VERSION = '0.0.2'
5
- end
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'miron/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'miron'
8
- spec.version = Miron::VERSION
9
- spec.authors = 'Jon Moss'
10
- spec.email = 'me@jonathanmoss.me'
11
-
12
- spec.summary = 'A redesigned Ruby web interface.'
13
- spec.description = 'A redesigned Ruby web interface.'
14
- spec.homepage = 'https://github.com/mironrb/miron'
15
- spec.license = 'MIT'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ['lib']
21
-
22
- spec.add_runtime_dependency 'activesupport'
23
- spec.add_runtime_dependency 'claide'
24
- spec.add_runtime_dependency 'multi_json'
25
-
26
- spec.add_development_dependency 'bundler', '~> 1.10'
27
- spec.add_development_dependency 'httparty'
28
- spec.add_development_dependency 'pry'
29
- spec.add_development_dependency 'puma'
30
- spec.add_development_dependency 'rake', '~> 10.0'
31
- spec.add_development_dependency 'rspec'
32
- spec.add_development_dependency 'rubocop'
33
- spec.add_development_dependency 'thin'
34
- spec.add_development_dependency 'unicorn'
35
- spec.add_development_dependency 'yard'
36
- end