rack-transcribr 0.0.2

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bbda873718492e58ef52df33a5431ddae4d73719
4
+ data.tar.gz: cc1b1bc1ee25d29ff81058280821c6b07d8b28a9
5
+ SHA512:
6
+ metadata.gz: b39daf3aeda585b1336ee9e8d749511ce122da9c2e906fc3872824b85aac09bdcde90302623fb4f6a8feabcfafbf75f2373b0a547711abc43285301c2ff9a08b
7
+ data.tar.gz: f0fb93171622104d1b2937e360cf10db5ac39ad28537d90b5ba7682acf6d59e370fe52b8b3d905464bad0cd53388d87a31928e9d59648dfe8dfc8e954d02a6e4
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transcribr.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Justin Okamoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Rack-Transcribr
2
+
3
+ I'm experimenting with creating Rack middleware gems. This lightweight gem servers as a replacement to Rack's CommonLogger statements. Improvements include colorized terminal output based on HTTP request method.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rack-transcribr'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rack-transcribr
20
+
21
+ ## Usage
22
+
23
+ Simply install in your rack app.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/justinokamoto/rack-transcribr/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/transcribr"
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
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
1
+ require 'rack/transcribr'
@@ -0,0 +1,74 @@
1
+ require 'rack/body_proxy'
2
+ require "rack/transcribr/extensions"
3
+
4
+ module Rack
5
+
6
+ class CommonLogger
7
+ def log(env, status, header, began_at) end # Disable CommonLogger middleware
8
+ end
9
+
10
+ class Transcribr
11
+
12
+ FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
13
+
14
+ def initialize(app, logger=nil)
15
+ @app = app
16
+ @logger = logger
17
+ end
18
+
19
+ def call(env)
20
+ began_at = Time.now
21
+ status, header, body = @app.call(env)
22
+ header = Utils::HeaderHash.new(header)
23
+ body = BodyProxy.new(body) { log(env, status, header, began_at) }
24
+ [status, header, body]
25
+ end
26
+
27
+ private
28
+
29
+ def log(env, status, header, began_at)
30
+ now = Time.now
31
+ length = extract_content_length(header)
32
+
33
+ msg = FORMAT % [
34
+ env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
35
+ env["REMOTE_USER"] || "-",
36
+ now.strftime("%d/%b/%Y:%H:%M:%S %z"),
37
+ env["REQUEST_METHOD"],
38
+ env["PATH_INFO"],
39
+ env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
40
+ env["HTTP_VERSION"],
41
+ status.to_s[0..3],
42
+ length,
43
+ now - began_at ]
44
+
45
+ logger = @logger || env["rack.errors"]
46
+
47
+ if logger.respond_to?(:write)
48
+ logger.write(colorize(env["REQUEST_METHOD"], msg))
49
+ else
50
+ logger << colorize(env["REQUEST_METHOD"], msg)
51
+ end
52
+ end
53
+
54
+ def extract_content_length(headers)
55
+ value = headers["CONTENT_LENGTH"] or return '-'
56
+ value.to_s == '0' ? '-' : value
57
+ end
58
+
59
+ def colorize(method, msg)
60
+ case method
61
+ when "GET"
62
+ msg.blue
63
+ when "POST"
64
+ msg.green
65
+ when "PUT", "PATCH"
66
+ msg.yellow
67
+ when "DELETE"
68
+ msg.red
69
+ else
70
+ msg
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,29 @@
1
+ class String
2
+ def colorize(color_code)
3
+ "\e[#{color_code}m#{self}\e[0m"
4
+ end
5
+
6
+ def red
7
+ colorize(31)
8
+ end
9
+
10
+ def green
11
+ colorize(32)
12
+ end
13
+
14
+ def yellow
15
+ colorize(33)
16
+ end
17
+
18
+ def blue
19
+ colorize(34)
20
+ end
21
+
22
+ def pink
23
+ colorize(35)
24
+ end
25
+
26
+ def light_blue
27
+ colorize(36)
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Transcribr
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/transcribr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-transcribr"
8
+ spec.version = Rack::Transcribr::VERSION
9
+ spec.authors = ["Justin Okamoto"]
10
+ spec.email = ["justin@gmail.com"]
11
+
12
+ spec.summary = %q{ This gem is a replacement for Rack's CommonLogger }
13
+ spec.description = %q{ I'm experimenting with creating Rack middleware gems. This lightweight gem servers as a replacement to Rack's CommonLogger statements. Improvements include colorized terminal output based on HTTP request method. }
14
+ spec.homepage = "https://github.com/justinokamoto/rack-transcribr.git"
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_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-transcribr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Justin Okamoto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: " I'm experimenting with creating Rack middleware gems. This lightweight
42
+ gem servers as a replacement to Rack's CommonLogger statements. Improvements include
43
+ colorized terminal output based on HTTP request method. "
44
+ email:
45
+ - justin@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/rack-transcribr.rb
60
+ - lib/rack/transcribr.rb
61
+ - lib/rack/transcribr/extensions.rb
62
+ - lib/rack/transcribr/version.rb
63
+ - rack-transcribr.gemspec
64
+ homepage: https://github.com/justinokamoto/rack-transcribr.git
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: This gem is a replacement for Rack's CommonLogger
88
+ test_files: []
89
+ has_rdoc: