rack-static-if-present 0.1.0 → 0.2.0

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/.gitignore CHANGED
@@ -17,5 +17,5 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
-
20
+ .bundle
21
21
  ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-static-if-present.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-static-if-present (0.2.0)
5
+ rack (~> 1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rack (1.3.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ rack-static-if-present!
data/Rakefile CHANGED
@@ -1,52 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rack-static-if-present"
8
- gem.summary = "Like Rack::Static. Except only if there is a static file to serve."
9
- gem.description = "Not much to explain. Not a lot of code, but wanted it packaged up for easy use/deployment."
10
- gem.email = "samsm@samsm.com"
11
- gem.homepage = "http://github.com/samsm/rack-static-if-present"
12
- gem.authors = ["Sam Schenkman-Moore"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
- end
19
-
20
- require 'rake/testtask'
21
- Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
23
- test.pattern = 'test/**/test_*.rb'
24
- test.verbose = true
25
- end
26
-
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
38
- end
39
-
40
- task :test => :check_dependencies
41
-
42
- task :default => :test
43
-
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "rack-static-if-present #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/config.ru ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rack'
3
+ require 'lib/rack-static-if-present'
4
+
5
+ class HelloWorld
6
+ def call(env)
7
+ [200, {"Content-Type" => "text/plain"}, ["Apparently no static file here."]]
8
+ end
9
+ end
10
+
11
+ # Run in this directory, the files in this project should get served (for example: http://localhost:9292/Rakefile).
12
+ use Rack::StaticIfPresent, :urls => ['/']
13
+
14
+ run HelloWorld.new
@@ -0,0 +1,9 @@
1
+ module Rack
2
+ module Static
3
+ module If
4
+ module Present
5
+ VERSION = "0.2.0"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,21 +1,28 @@
1
- class Rack::StaticIfPresent
2
-
3
- def initialize(app, options={})
4
- @app = app
5
- @urls = options[:urls] || ["/favicon.ico"]
6
- root = options[:root] || Dir.pwd
7
- @file_server = Rack::File.new(root)
8
- end
9
-
10
- def call(env)
11
- path = env["PATH_INFO"]
12
- can_serve = @urls.any? { |url| path.index(url) == 0 }
13
-
14
- if can_serve
15
- result = @file_server.call(env)
16
- return result if result[0] == 200
1
+ module Rack
2
+ class StaticIfPresent
3
+ def initialize(app, options={})
4
+ @app = app
5
+ @urls = options[:urls] || ["/favicon.ico"]
6
+ root = options[:root] || Dir.pwd
7
+ cache_control = options[:cache_control]
8
+ @file_server = Rack::File.new(root, cache_control)
9
+ end
10
+
11
+ def call(env)
12
+ path = env["PATH_INFO"]
13
+
14
+ unless @urls.kind_of? Hash
15
+ can_serve = @urls.any? { |url| path.index(url) == 0 }
16
+ else
17
+ can_serve = @urls.key? path
18
+ end
19
+
20
+ if can_serve
21
+ env["PATH_INFO"] = @urls[path] if @urls.kind_of? Hash
22
+ file = @file_server.call(env)
23
+ return file if file[0] == 200
24
+ end
25
+ @app.call(env)
17
26
  end
18
- @app.call(env)
19
27
  end
20
-
21
28
  end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack-static-if-present/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-static-if-present"
7
+ s.version = Rack::Static::If::Present::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Sam Schenkman-Moore"]
10
+ s.email = ["samsm@samsm.com"]
11
+ s.homepage = "http://github.com/samsm/rack-static-if-present"
12
+ s.summary = %q{Like Rack::Static. Except only if there is a static file to serve.}
13
+ s.description = %q{Not much to explain. Not a lot of code, but wanted it packaged up for easy use/deployment.}
14
+
15
+ s.rubyforge_project = "rack-static-if-present"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'rack', ['~> 1']
23
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-static-if-present
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sam Schenkman-Moore
@@ -9,27 +15,44 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-15 00:00:00 -05:00
18
+ date: 2011-05-24 00:00:00 -04:00
13
19
  default_executable:
14
- dependencies: []
15
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 1
32
+ version: "1"
33
+ type: :runtime
34
+ version_requirements: *id001
16
35
  description: Not much to explain. Not a lot of code, but wanted it packaged up for easy use/deployment.
17
- email: samsm@samsm.com
36
+ email:
37
+ - samsm@samsm.com
18
38
  executables: []
19
39
 
20
40
  extensions: []
21
41
 
22
- extra_rdoc_files:
23
- - LICENSE
24
- - README.rdoc
42
+ extra_rdoc_files: []
43
+
25
44
  files:
26
45
  - .document
27
46
  - .gitignore
47
+ - Gemfile
48
+ - Gemfile.lock
28
49
  - LICENSE
29
50
  - README.rdoc
30
51
  - Rakefile
31
- - VERSION
52
+ - config.ru
32
53
  - lib/rack-static-if-present.rb
54
+ - lib/rack-static-if-present/version.rb
55
+ - rack-static-if-present.gemspec
33
56
  - test/helper.rb
34
57
  - test/test_rack-static-if-present.rb
35
58
  has_rdoc: true
@@ -37,26 +60,32 @@ homepage: http://github.com/samsm/rack-static-if-present
37
60
  licenses: []
38
61
 
39
62
  post_install_message:
40
- rdoc_options:
41
- - --charset=UTF-8
63
+ rdoc_options: []
64
+
42
65
  require_paths:
43
66
  - lib
44
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
45
69
  requirements:
46
70
  - - ">="
47
71
  - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
48
75
  version: "0"
49
- version:
50
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
51
78
  requirements:
52
79
  - - ">="
53
80
  - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
54
84
  version: "0"
55
- version:
56
85
  requirements: []
57
86
 
58
- rubyforge_project:
59
- rubygems_version: 1.3.5
87
+ rubyforge_project: rack-static-if-present
88
+ rubygems_version: 1.3.7
60
89
  signing_key:
61
90
  specification_version: 3
62
91
  summary: Like Rack::Static. Except only if there is a static file to serve.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0