mongomapper_ext 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -42,7 +42,7 @@ module MongoMapperExt
42
42
  end
43
43
 
44
44
  def get
45
- gridfs.get(grid_filename)
45
+ @io ||= gridfs.get(grid_filename)
46
46
  end
47
47
 
48
48
  def grid_filename
@@ -62,6 +62,7 @@ module MongoMapperExt
62
62
  end
63
63
 
64
64
  def delete
65
+ @io = nil
65
66
  gridfs.delete(grid_filename)
66
67
  end
67
68
 
@@ -0,0 +1,69 @@
1
+ require 'time'
2
+ require 'rack/utils'
3
+
4
+ module MongoMapperExt
5
+ class FileServer
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ if env["PATH_INFO"] =~ /^\/_files\/([^\/?]+)/
12
+ @model = $1.classify.constantize rescue nil
13
+ return forbidden if @model.nil?
14
+
15
+ dup._call(env)
16
+ else
17
+ @app.call(env)
18
+ end
19
+ end
20
+
21
+ def _call(env)
22
+ request = Rack::Request.new(env)
23
+ params = request.GET
24
+
25
+ @file = @model.find_file_from_params(params, request)
26
+ return not_found if @file.nil?
27
+
28
+ if @file.present?
29
+ serving
30
+ else
31
+ not_found
32
+ end
33
+ end
34
+
35
+ def forbidden
36
+ body = "Forbidden\n"
37
+ [403, {"Content-Type" => "text/plain",
38
+ "Content-Length" => body.size.to_s,
39
+ "X-Cascade" => "pass"},
40
+ [body]]
41
+ end
42
+
43
+ def serving
44
+ body = self
45
+ [200, {
46
+ "Last-Modified" => Time.now.httpdate,
47
+ "Content-Type" => @file.content_type,
48
+ "Content-Length" => @file.size.to_s
49
+ }, body]
50
+ end
51
+
52
+ def not_found
53
+ body = "File not found: #{@path_info}\n"
54
+ [404, {"Content-Type" => "text/plain",
55
+ "Content-Length" => body.size.to_s,
56
+ "X-Cascade" => "pass"},
57
+ [body]]
58
+ end
59
+
60
+ def each
61
+ f = @file.get
62
+ while part = f.read(8192)
63
+ yield part
64
+ break if part.empty?
65
+ end
66
+ end
67
+ end
68
+ end
69
+
@@ -25,6 +25,7 @@ require 'mongomapper_ext/types/translation'
25
25
  require 'mongomapper_ext/file_list'
26
26
  require 'mongomapper_ext/file'
27
27
  require 'mongomapper_ext/storage'
28
+ require 'mongomapper_ext/file_server'
28
29
 
29
30
  # update
30
31
  require 'mongomapper_ext/update'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongomapper_ext}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David A. Cuadrado"]
12
- s.date = %q{2010-06-20}
12
+ s.date = %q{2010-09-28}
13
13
  s.description = %q{MongoMapper extensions}
14
14
  s.email = %q{krawek@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/mongomapper_ext.rb",
36
36
  "lib/mongomapper_ext/file.rb",
37
37
  "lib/mongomapper_ext/file_list.rb",
38
+ "lib/mongomapper_ext/file_server.rb",
38
39
  "lib/mongomapper_ext/filter.rb",
39
40
  "lib/mongomapper_ext/js/filter.js",
40
41
  "lib/mongomapper_ext/js/find_tags.js",
@@ -63,7 +64,7 @@ Gem::Specification.new do |s|
63
64
  s.homepage = %q{http://github.com/dcu/mongomapper_ext}
64
65
  s.rdoc_options = ["--charset=UTF-8"]
65
66
  s.require_paths = ["lib"]
66
- s.rubygems_version = %q{1.3.6}
67
+ s.rubygems_version = %q{1.3.7}
67
68
  s.summary = %q{MongoMapper extensions}
68
69
  s.test_files = [
69
70
  "test/test_slugizer.rb",
@@ -91,7 +92,7 @@ Gem::Specification.new do |s|
91
92
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
92
93
  s.specification_version = 3
93
94
 
94
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
95
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
95
96
  s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.8"])
96
97
  s.add_runtime_dependency(%q<uuidtools>, [">= 2.0.0"])
97
98
  s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomapper_ext
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 4
8
+ - 5
8
9
  - 0
9
- version: 0.4.0
10
+ version: 0.5.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - David A. Cuadrado
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-20 00:00:00 -05:00
18
+ date: 2010-09-28 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: mongo_mapper
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 27
27
30
  segments:
28
31
  - 0
29
32
  - 8
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: uuidtools
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 15
40
45
  segments:
41
46
  - 2
42
47
  - 0
@@ -48,9 +53,11 @@ dependencies:
48
53
  name: shoulda
49
54
  prerelease: false
50
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
51
57
  requirements:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
60
+ hash: 35
54
61
  segments:
55
62
  - 2
56
63
  - 10
@@ -62,9 +69,11 @@ dependencies:
62
69
  name: jnunemaker-matchy
63
70
  prerelease: false
64
71
  requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
65
73
  requirements:
66
74
  - - "="
67
75
  - !ruby/object:Gem::Version
76
+ hash: 15
68
77
  segments:
69
78
  - 0
70
79
  - 4
@@ -76,9 +85,11 @@ dependencies:
76
85
  name: mocha
77
86
  prerelease: false
78
87
  requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
79
89
  requirements:
80
90
  - - ">="
81
91
  - !ruby/object:Gem::Version
92
+ hash: 51
82
93
  segments:
83
94
  - 0
84
95
  - 9
@@ -114,6 +125,7 @@ files:
114
125
  - lib/mongomapper_ext.rb
115
126
  - lib/mongomapper_ext/file.rb
116
127
  - lib/mongomapper_ext/file_list.rb
128
+ - lib/mongomapper_ext/file_server.rb
117
129
  - lib/mongomapper_ext/filter.rb
118
130
  - lib/mongomapper_ext/js/filter.js
119
131
  - lib/mongomapper_ext/js/find_tags.js
@@ -149,23 +161,27 @@ rdoc_options:
149
161
  require_paths:
150
162
  - lib
151
163
  required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
152
165
  requirements:
153
166
  - - ">="
154
167
  - !ruby/object:Gem::Version
168
+ hash: 3
155
169
  segments:
156
170
  - 0
157
171
  version: "0"
158
172
  required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
159
174
  requirements:
160
175
  - - ">="
161
176
  - !ruby/object:Gem::Version
177
+ hash: 3
162
178
  segments:
163
179
  - 0
164
180
  version: "0"
165
181
  requirements: []
166
182
 
167
183
  rubyforge_project:
168
- rubygems_version: 1.3.6
184
+ rubygems_version: 1.3.7
169
185
  signing_key:
170
186
  specification_version: 3
171
187
  summary: MongoMapper extensions