sinatra-whoami 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.
- data/Gemfile +3 -0
- data/Gemfile.lock +26 -0
- data/README.md +19 -0
- data/Rakefile +10 -0
- data/lib/sinatra/whoami.rb +44 -0
- data/sinatra-whoami.gemspec +20 -0
- data/test/test_helper.rb +14 -0
- data/test/whoami_test.rb +18 -0
- metadata +87 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
sinatra-whoami (0.0.1)
|
|
5
|
+
sinatra (~> 1.4.2)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: http://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
rack (1.5.2)
|
|
11
|
+
rack-protection (1.5.0)
|
|
12
|
+
rack
|
|
13
|
+
rack-test (0.6.2)
|
|
14
|
+
rack (>= 1.0)
|
|
15
|
+
sinatra (1.4.2)
|
|
16
|
+
rack (~> 1.5, >= 1.5.2)
|
|
17
|
+
rack-protection (~> 1.4)
|
|
18
|
+
tilt (~> 1.3, >= 1.3.4)
|
|
19
|
+
tilt (1.4.1)
|
|
20
|
+
|
|
21
|
+
PLATFORMS
|
|
22
|
+
ruby
|
|
23
|
+
|
|
24
|
+
DEPENDENCIES
|
|
25
|
+
rack-test (~> 0.6.2)
|
|
26
|
+
sinatra-whoami!
|
data/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Sinatra Whoami
|
|
2
|
+
|
|
3
|
+
Sinatra extension that adds the original route signature to the `sinatra.route` env so that you can log it for better endpoint-specific metrics, monitoring and alerting.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
class MyApplication < Sinatra::Base
|
|
9
|
+
register Sinatra::Whoami
|
|
10
|
+
|
|
11
|
+
after do
|
|
12
|
+
log :route => env["sinatra.route"] # ie "/products/:id/photos"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
Released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "sinatra/base"
|
|
2
|
+
|
|
3
|
+
module Sinatra
|
|
4
|
+
module Whoami
|
|
5
|
+
# redefine compile! to store the original path with the route signature
|
|
6
|
+
def compile!(verb, path, block, options = {})
|
|
7
|
+
options.each_pair { |option, args| send(option, *args) }
|
|
8
|
+
method_name = "#{verb} #{path}"
|
|
9
|
+
unbound_method = generate_method(method_name, &block)
|
|
10
|
+
pattern, keys = compile path
|
|
11
|
+
conditions, @conditions = @conditions, []
|
|
12
|
+
|
|
13
|
+
[ pattern, keys, conditions, path, block.arity != 0 ?
|
|
14
|
+
proc { |a,p| unbound_method.bind(a).call(*p) } :
|
|
15
|
+
proc { |a,p| unbound_method.bind(a).call } ]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.registered(app)
|
|
19
|
+
app.send(:include, Router)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module Router
|
|
23
|
+
# redefine route! to save the route path in env
|
|
24
|
+
def route!(base = settings, pass_block=nil)
|
|
25
|
+
if routes = base.routes[@request.request_method]
|
|
26
|
+
routes.each do |pattern, keys, conditions, path, block|
|
|
27
|
+
pass_block = process_route(pattern, keys, conditions) do |*args|
|
|
28
|
+
@env["sinatra.route"] = path
|
|
29
|
+
route_eval { block[*args] }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Run routes defined in superclass.
|
|
35
|
+
if base.superclass.respond_to?(:routes)
|
|
36
|
+
return route!(base.superclass, pass_block)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
route_eval(&pass_block) if pass_block
|
|
40
|
+
route_missing
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = "sinatra-whoami"
|
|
6
|
+
s.version = "0.0.1"
|
|
7
|
+
s.authors = ["Pedro Belo"]
|
|
8
|
+
s.email = ["pedro@heroku.com"]
|
|
9
|
+
s.homepage = "http://github.com/pedro/sinatra-whoami"
|
|
10
|
+
s.summary = %q{Sinatra extension to give routes their own path}
|
|
11
|
+
s.description = %q{Sinatra extension to give routes their own path}
|
|
12
|
+
|
|
13
|
+
s.files = `git ls-files`.split("\n")
|
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
|
|
18
|
+
s.add_runtime_dependency 'sinatra', '~> 1.4.2'
|
|
19
|
+
s.add_development_dependency 'rack-test', '~> 0.6.2'
|
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "minitest/spec"
|
|
2
|
+
require "minitest/autorun"
|
|
3
|
+
require "rack/test"
|
|
4
|
+
require "sinatra/whoami"
|
|
5
|
+
|
|
6
|
+
class MiniTest::Unit::TestCase
|
|
7
|
+
include Rack::Test::Methods
|
|
8
|
+
|
|
9
|
+
attr_reader :app
|
|
10
|
+
|
|
11
|
+
def mock_app(base=Sinatra::Base, &block)
|
|
12
|
+
@app = Sinatra.new(base, &block)
|
|
13
|
+
end
|
|
14
|
+
end
|
data/test/whoami_test.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
describe Sinatra::Whoami do
|
|
4
|
+
def app
|
|
5
|
+
mock_app {
|
|
6
|
+
register Sinatra::Whoami
|
|
7
|
+
|
|
8
|
+
get "/products/:id/photos" do
|
|
9
|
+
env["sinatra.route"]
|
|
10
|
+
end
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "register a helper with the current route name" do
|
|
15
|
+
get "/products/42/photos"
|
|
16
|
+
last_response.body.must_equal("/products/:id/photos")
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sinatra-whoami
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Pedro Belo
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: sinatra
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 1.4.2
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 1.4.2
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rack-test
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 0.6.2
|
|
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.6.2
|
|
46
|
+
description: Sinatra extension to give routes their own path
|
|
47
|
+
email:
|
|
48
|
+
- pedro@heroku.com
|
|
49
|
+
executables: []
|
|
50
|
+
extensions: []
|
|
51
|
+
extra_rdoc_files: []
|
|
52
|
+
files:
|
|
53
|
+
- Gemfile
|
|
54
|
+
- Gemfile.lock
|
|
55
|
+
- README.md
|
|
56
|
+
- Rakefile
|
|
57
|
+
- lib/sinatra/whoami.rb
|
|
58
|
+
- sinatra-whoami.gemspec
|
|
59
|
+
- test/test_helper.rb
|
|
60
|
+
- test/whoami_test.rb
|
|
61
|
+
homepage: http://github.com/pedro/sinatra-whoami
|
|
62
|
+
licenses: []
|
|
63
|
+
post_install_message:
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
none: false
|
|
69
|
+
requirements:
|
|
70
|
+
- - ! '>='
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ! '>='
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 1.8.22
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 3
|
|
84
|
+
summary: Sinatra extension to give routes their own path
|
|
85
|
+
test_files:
|
|
86
|
+
- test/test_helper.rb
|
|
87
|
+
- test/whoami_test.rb
|