rack-accept 0.4.1 → 0.4.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.
data/README CHANGED
@@ -31,7 +31,7 @@ Usage
31
31
  Rack::Accept implements the Rack middleware interface and may be used with any
32
32
  Rack-based application. Simply insert the Rack::Accept module in your Rack
33
33
  middleware pipeline and access the Rack::Accept::Request object in the
34
- "rack-accept.request" environment key, as in the following example:
34
+ "rack-accept.request" environment key, as in the following example.
35
35
 
36
36
  require 'rack/accept'
37
37
 
@@ -105,7 +105,7 @@ Four-letter Words
105
105
  License
106
106
  -------
107
107
 
108
- Copyright 2010 Michael J. I. Jackson
108
+ Copyright 2010 Michael Jackson
109
109
 
110
110
  Permission is hereby granted, free of charge, to any person obtaining a copy
111
111
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -49,16 +49,16 @@ end
49
49
  # PACKAGING & INSTALLATION ####################################################
50
50
 
51
51
  if defined?(Gem)
52
- $spec = eval("#{File.read('.gemspec')}")
52
+ $spec = eval("#{File.read('rack-accept.gemspec')}")
53
53
 
54
54
  directory 'dist'
55
55
 
56
56
  def package(ext='')
57
- "dist/rack-accept-#{$spec.version}" + ext
57
+ "dist/#{$spec.name}-#{$spec.version}" + ext
58
58
  end
59
59
 
60
60
  file package('.gem') => %w< dist > + $spec.files do |f|
61
- sh "gem build .gemspec"
61
+ sh "gem build rack-accept.gemspec"
62
62
  mv File.basename(f.name), f.name
63
63
  end
64
64
 
@@ -4,7 +4,7 @@ Usage
4
4
  Rack::Accept implements the Rack middleware interface and may be used with any
5
5
  Rack-based application. Simply insert the Rack::Accept module in your Rack
6
6
  middleware pipeline and access the [Request][req] object in the
7
- "rack-accept.request" environment key, as in the following example:
7
+ "rack-accept.request" environment key, as in the following example.
8
8
 
9
9
  require 'rack/accept'
10
10
 
@@ -1,11 +1,12 @@
1
1
  require 'rack'
2
2
 
3
+ # HTTP Accept* for Ruby/Rack.
4
+ #
5
+ # http://mjijackson.com/rack-accept
3
6
  module Rack::Accept
7
+ VERSION = [0, 4, 2]
4
8
 
5
- # The current version of rack-accept.
6
- VERSION = [0, 4, 1]
7
-
8
- # Returns the current version of rack-accept as a string.
9
+ # Returns the current version of Rack::Accept as a string.
9
10
  def self.version
10
11
  VERSION.join('.')
11
12
  end
@@ -23,5 +24,4 @@ module Rack::Accept
23
24
  autoload :MediaType, 'rack/accept/media_type'
24
25
  autoload :Request, 'rack/accept/request'
25
26
  autoload :Response, 'rack/accept/response'
26
-
27
27
  end
@@ -4,8 +4,7 @@ module Rack::Accept
4
4
  # specification, and provides several convenience methods for determining
5
5
  # acceptable character sets.
6
6
  #
7
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more
8
- # information.
7
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2
9
8
  class Charset
10
9
 
11
10
  include Header
@@ -4,8 +4,7 @@ module Rack::Accept
4
4
  # specification, and provides several convenience methods for determining
5
5
  # acceptable content encodings.
6
6
  #
7
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more
8
- # information.
7
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
9
8
  class Encoding
10
9
 
11
10
  include Header
@@ -12,8 +12,8 @@ module Rack::Accept
12
12
  def parse(header)
13
13
  qvalues = {}
14
14
 
15
- header.to_s.split(/,\s*/).map do |part|
16
- m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick
15
+ header.to_s.split(/,\s*/).each do |part|
16
+ m = /^([^\s,]+?)(?:\s*;\s*q\s*=\s*(\d+(?:\.\d+)?))?$/.match(part)
17
17
 
18
18
  if m
19
19
  qvalues[m[1]] = normalize_qvalue((m[2] || 1).to_f)
@@ -4,8 +4,7 @@ module Rack::Accept
4
4
  # specification, and provides several convenience methods for determining
5
5
  # acceptable content languages.
6
6
  #
7
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more
8
- # information.
7
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
9
8
  class Language
10
9
 
11
10
  include Header
@@ -4,8 +4,7 @@ module Rack::Accept
4
4
  # and provides several convenience methods for determining acceptable media
5
5
  # types.
6
6
  #
7
- # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more
8
- # information.
7
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
9
8
  class MediaType
10
9
 
11
10
  include Header
@@ -42,6 +41,16 @@ module Rack::Accept
42
41
 
43
42
  private
44
43
 
44
+ def initialize(header)
45
+ # Strip accept-extension for now. We may want to do something with this
46
+ # later if people actually start to use it.
47
+ header = header.to_s.split(/,\s*/).map {|part|
48
+ part.sub(/(;\s*q\s*=\s*[\d.]+).*$/, '\1')
49
+ }.join(', ')
50
+
51
+ super(header)
52
+ end
53
+
45
54
  # Returns true if all parameters and values in +match+ are also present in
46
55
  # +params+.
47
56
  def params_match?(params, match)
@@ -49,5 +58,6 @@ module Rack::Accept
49
58
  parsed = parse_range_params(params)
50
59
  parsed == parsed.merge(parse_range_params(match))
51
60
  end
61
+
52
62
  end
53
63
  end
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rack-accept'
3
- s.version = '0.4.1'
4
- s.date = '2010-04-05'
3
+ s.version = '0.4.2'
4
+ s.date = '2010-05-04'
5
5
 
6
6
  s.summary = 'HTTP Accept* for Ruby/Rack'
7
7
  s.description = 'HTTP Accept, Accept-Charset, Accept-Encoding, and Accept-Language for Ruby/Rack'
8
8
 
9
- s.author = 'Michael J. I. Jackson'
9
+ s.author = 'Michael Jackson'
10
10
  s.email = 'mjijackson@gmail.com'
11
11
 
12
12
  s.require_paths = %w< lib >
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.files = Dir['lib/**/*.rb'] +
15
15
  Dir['test/*.rb'] +
16
16
  Dir['doc/**/*'] +
17
- %w< CHANGES .gemspec Rakefile README >
17
+ %w< CHANGES rack-accept.gemspec Rakefile README >
18
18
 
19
19
  s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/ }
20
20
 
@@ -25,5 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.rdoc_options = %w< --line-numbers --inline-source --title Rack::Accept --main Rack::Accept >
26
26
  s.extra_rdoc_files = %w< CHANGES README >
27
27
 
28
- s.homepage = 'http://mjijackson.github.com/rack-accept'
28
+ s.homepage = 'http://mjijackson.com/rack-accept'
29
29
  end
@@ -39,4 +39,9 @@ class MediaTypeTest < Test::Unit::TestCase
39
39
  assert_equal('text/xml', m.best_of(%w< text/xml text/html >))
40
40
  end
41
41
 
42
+ def test_extension
43
+ m = M.new('text/*;q=0.5;a=42')
44
+ assert_equal(0.5, m.qvalue('text/plain'))
45
+ end
46
+
42
47
  end
metadata CHANGED
@@ -5,16 +5,16 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
- - Michael J. I. Jackson
12
+ - Michael Jackson
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-05 00:00:00 -06:00
17
+ date: 2010-05-04 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -75,11 +75,11 @@ files:
75
75
  - doc/license.markdown
76
76
  - doc/usage.markdown
77
77
  - CHANGES
78
- - .gemspec
78
+ - rack-accept.gemspec
79
79
  - Rakefile
80
80
  - README
81
81
  has_rdoc: true
82
- homepage: http://mjijackson.github.com/rack-accept
82
+ homepage: http://mjijackson.com/rack-accept
83
83
  licenses: []
84
84
 
85
85
  post_install_message: