mynyml-rack-abstract-format 0.9 → 0.9.4

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
@@ -9,6 +9,8 @@ always point to the same action independently from the requested format.
9
9
 
10
10
  USAGE
11
11
 
12
+ require 'rack/abstract_format'
13
+
12
14
  use Rack::AbstractFormat
13
15
  run app
14
16
 
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = 'rack-abstract-format'
25
- s.version = '0.9'
25
+ s.version = '0.9.4'
26
26
  s.summary = "Rack middleware that abstracts format (extension) away from the path (into env)"
27
27
  s.description = "Rack middleware that abstracts format (extension) away from the path (into env)"
28
28
  s.author = "Martin Aumont"
@@ -1,5 +1,5 @@
1
1
  # run me with:
2
- # $rackup examples/app.rb
2
+ # $rackup examples/app.ru -p 3000
3
3
  #
4
4
  require 'rubygems'
5
5
  require 'rack'
@@ -11,7 +11,7 @@ class App
11
11
  env['PATH_INFO'] #=> #{env['PATH_INFO'].inspect}
12
12
  env['request.format'] #=> #{env['request.format'].inspect}
13
13
  TXT
14
- [200, {'Content-Type' => 'text/plain'}, [body]]
14
+ [200, {'Content-Type' => 'text/plain'}, [body]]
15
15
  end
16
16
  end
17
17
 
@@ -10,8 +10,13 @@ module Rack
10
10
  def call(env)
11
11
  path = Pathname(env['PATH_INFO'])
12
12
  env['PATH_INFO'] = path.to_s.sub(/#{path.extname}$/,'')
13
- env['request.format'] = path.extname.sub(/^\./,'')
13
+ env['Accept'] = concat(env['Accept'], Rack::Mime.mime_type(path.extname))
14
14
  @app.call(env)
15
15
  end
16
+
17
+ private
18
+ def concat(accept, type)
19
+ (accept || '').split(',').unshift(type).join(',')
20
+ end
16
21
  end
17
22
  end
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
- name: simple_router
2
+ name: rack-abstract-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-21 00:00:00 -04:00
12
+ date: 2009-06-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Rack middleware that abstracts format information (extension) away from the path (into env)
16
+ description: Rack middleware that abstracts format (extension) away from the path (into env)
17
17
  email: mynyml@gmail.com
18
18
  executables: []
19
19
 
@@ -26,6 +26,9 @@ files:
26
26
  - test
27
27
  - test/test_abstract_format.rb
28
28
  - test/test_helper.rb
29
+ - examples
30
+ - examples/app.ru
31
+ - rack-abstract-format.gemspec
29
32
  - lib
30
33
  - lib/rack
31
34
  - lib/rack/abstract_format.rb
@@ -58,6 +61,6 @@ rubyforge_project:
58
61
  rubygems_version: 1.3.3
59
62
  signing_key:
60
63
  specification_version: 3
61
- summary: Rack middleware that abstracts format information (extension) away from the path (into env)
64
+ summary: Rack middleware that abstracts format (extension) away from the path (into env)
62
65
  test_files: []
63
66
 
@@ -8,9 +8,9 @@ App = Rack::Builder.new {
8
8
 
9
9
  class AbstractFormatTest < Test::Unit::TestCase
10
10
 
11
- def get(path)
12
- env = Rack::MockRequest.env_for(path)
13
- App.call(env).last
11
+ def get(path, opts={})
12
+ env = Rack::MockRequest.env_for(path, opts)
13
+ App.call(env)
14
14
  env
15
15
  end
16
16
 
@@ -24,8 +24,8 @@ class AbstractFormatTest < Test::Unit::TestCase
24
24
  assert_equal '/path.to/resource', env['PATH_INFO']
25
25
  end
26
26
 
27
- test "stores format in environment" do
28
- env = get('/path.to/resource.xml')
29
- assert_equal 'xml', env['request.format']
27
+ test "prepends requested media type to Accept header" do
28
+ env = get('/path/resource.html', 'Accept' => 'application/xml')
29
+ assert_equal 'text/html,application/xml' , env['Accept']
30
30
  end
31
31
  end
data/test/test_helper.rb CHANGED
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'rack'
5
5
  begin
6
6
  require 'ruby-debug'
7
+ require 'phocus/test_unit'
7
8
  rescue LoadError, RuntimeError
8
9
  end
9
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mynyml-rack-abstract-format
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.9"
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-20 21:00:00 -07:00
12
+ date: 2009-06-01 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,8 +27,8 @@ files:
27
27
  - test/test_abstract_format.rb
28
28
  - test/test_helper.rb
29
29
  - examples
30
- - examples/app.rb
31
- - simple_router.gemspec
30
+ - examples/app.ru
31
+ - rack-abstract-format.gemspec
32
32
  - lib
33
33
  - lib/rack
34
34
  - lib/rack/abstract_format.rb