roy 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roy (0.3.1)
4
+ roy (0.3.2)
5
5
  rack
6
6
 
7
7
  GEM
data/lib/roy.rb CHANGED
@@ -31,15 +31,14 @@ module Roy
31
31
  }
32
32
 
33
33
  method = roy.env['REQUEST_METHOD'].downcase.to_sym
34
- path = roy.env['PATH_INFO']
35
- path = "/#{path}" unless path[0] == '/'
34
+ roy.env['PATH_INFO'].sub!(/^([^\/])/, '/\1')
36
35
 
37
36
  method, was_head = :get, true if method == :head
38
37
 
39
38
  roy.response.status, body = catch(:halt) do
40
39
  halt(405) unless roy.conf.allow.include?(method)
41
40
  prefixed_method = :"#{roy.conf.prefix}#{method}"
42
- [roy.response.status, send(prefixed_method, path)]
41
+ [roy.response.status, send(prefixed_method, roy.env['PATH_INFO'])]
43
42
  end
44
43
 
45
44
  roy.response.write(body) unless was_head
@@ -1,22 +1,21 @@
1
1
  module Roy
2
2
  module Plugin
3
3
  module BasicAuth
4
- def protected!
5
- unless authorized?
4
+ def protected!(data=nil)
5
+ unless authorized?(data)
6
6
  realm = roy.conf.auth && roy.conf.auth[:realm] || 'Realm'
7
7
  roy.response['WWW-Authenticate'] = %(Basic realm="#{realm}")
8
8
  halt 401
9
9
  end
10
10
  end
11
11
 
12
- def authorized?
13
- @auth ||= Rack::Auth::Basic::Request.new(roy.request.env)
14
- (roy.conf.auth ||= {})[:credentials] ||= {'admin' => 'password'}
12
+ def authorized?(data=nil)
13
+ @auth ||= Rack::Auth::Basic::Request.new(roy.request.env)
15
14
 
16
15
  @auth.provided? && @auth.basic? && @auth.credentials &&
17
- roy.conf.auth[:credentials].any? do |user, password|
18
- [user, password] == @auth.credentials
19
- end
16
+ (roy.conf.auth[:logic] || ->(data, u, p) {
17
+ %w(admin password) == [u, p]
18
+ }).(data, *@auth.credentials)
20
19
  end
21
20
  end
22
21
  end
data/lib/roy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roy
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -8,7 +8,7 @@ class BasicAuthTestObject
8
8
  roy allow: [:get],
9
9
  auth: {
10
10
  realm: "Custom",
11
- credentials: {'user' => 'password'}
11
+ logic: ->(_, u, p) { %w(user password) == [u, p] }
12
12
  }
13
13
 
14
14
  def get(path)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-17 00:00:00.000000000 Z
12
+ date: 2011-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &9732340 !ruby/object:Gem::Requirement
16
+ requirement: &8277780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9732340
24
+ version_requirements: *8277780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &9731800 !ruby/object:Gem::Requirement
27
+ requirement: &8277280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *9731800
35
+ version_requirements: *8277280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack-test
38
- requirement: &9731300 !ruby/object:Gem::Requirement
38
+ requirement: &8276780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *9731300
46
+ version_requirements: *8276780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: tilt
49
- requirement: &9730800 !ruby/object:Gem::Requirement
49
+ requirement: &8276280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *9730800
57
+ version_requirements: *8276280
58
58
  description: ! 'roy is a small library which allows every Ruby object to be used
59
59
 
60
60
  as a Rack application.'