rack-gridfs 0.4.1 → 0.4.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab436c3dc05107e4b93ceea00c2a7fe0f78b226e
4
+ data.tar.gz: 2231fb606b3aed0c9ab17676308b7bfd8adc3ef7
5
+ SHA512:
6
+ metadata.gz: 2362e5546421a1257120ea3cae2bf6a79ff8960c2245ab9f58b4135bf9d4f72684f086e4d3c46b9072d2cbbd3578e63a594c607977434f4f666f3ccc7e89098b
7
+ data.tar.gz: 8f22ad6d2c767bda454a3deef0412cc206f232cb46f9504da80203eaa160d35dc8c13cec441e5b0400b0ec90dbf29dc434ce48419c1ea286fe4423fdca2f31a4
@@ -0,0 +1,75 @@
1
+ CHANGE LOG
2
+ ----------
3
+
4
+ ### 0.4.3 / November 4, 2015 ###
5
+
6
+ Same as v0.4.2, but v0.4.2 gem yanked because of faulty gemspec file (grumble).
7
+
8
+ ### 0.4.2 / November 3, 2015 ###
9
+
10
+ [full commit log](https://github.com/skinandbones/rack-gridfs/compare/v0.4.1...v0.4.2)
11
+
12
+ It's been awhile, eh? No compatibility with new `mongo` 2.x releases yet,
13
+ we'll look to bring that in an 0.5 or 1.0 release. This is primarily a bug fix
14
+ release for users affected by incompatible bson 2.x being allowed by some
15
+ historical `mongo` driver versions.
16
+
17
+ #### Features ####
18
+
19
+ - Eliminate need for `:require` option in Gemfile ([Konstantin Shabanov])
20
+ - Add `fs_name` option as supported by the Mongo driver ([max-power])
21
+
22
+ #### Bug Fixes ####
23
+
24
+ - Prevent bson 2.x being allowed to resolve dependency constraints, where some
25
+ historical versions of the `mongo` gem used a ">= 1.x" constraint spec.
26
+ See [#14](https://github.com/skinandbones/rack-gridfs/issues/14) for instance.
27
+
28
+
29
+ ### 0.4.1 / June 26, 2011 ###
30
+
31
+ [full commit log](https://github.com/skinandbones/rack-gridfs/compare/v0.4.0...v0.4.1)
32
+
33
+ #### Bug Fixes ####
34
+
35
+ - URL-decode before filename lookup so that non-ASCII filenames are handled
36
+ correctly ([Konstantin Shabanov])
37
+
38
+
39
+ ### 0.4.0 / May 12, 2011 ###
40
+
41
+ Major refactoring and loads of new features! Thanks to [Ben Marini] for his
42
+ substantial contributions to this release.
43
+
44
+ [full commit log](https://github.com/skinandbones/rack-gridfs/compare/v0.2.0...v0.4.0)
45
+
46
+ #### Features ####
47
+
48
+ - Allow configuration of MongoDB authentication ([Steve Sloan])
49
+ - Allow option to look up objects by GridFS filename instead of `ObjectId`
50
+ ([SHIBATA Hiroshi])
51
+ - Return iterable GridIO object instead of file contents, so Rack can stream in
52
+ chunks ([Ches Martin])
53
+ - `Rack::GridFS::Endpoint`: support for mounting as a Rack endpoint in addition
54
+ to middleware ([Ben Marini])
55
+ - Cache headers: set `Last-Modified` and `Etag` so that `Rack::ConditionalGet`
56
+ sends 304s. `expires` option to set `Cache-Control` ([Alexander Gräfe] & [Ben
57
+ Marini])
58
+ - `mime-types` dependency so GridFS lib can determine content types ([Ben
59
+ Marini])
60
+ - You can now pass a `Mongo::DB` instance instead of discrete database
61
+ configuration parameters. Connections are retried so we take advantage of a
62
+ `ReplSetConnection` in high-availability architectures ([Ben Marini])
63
+
64
+ #### Bug Fixes ####
65
+
66
+ - `BSON::ObjectID` renamed to `ObjectId`, and other changes supporting
67
+ current versions of Mongo libraries
68
+
69
+ [Alexander Gräfe]: https://github.com/rickenharp
70
+ [SHIBATA Hiroshi]: https://github.com/hsbt
71
+ [Ben Marini]: https://github.com/bmarini
72
+ [Ches Martin]: https://github.com/ches
73
+ [max-power]: https://github.com/max-power
74
+ [Konstantin Shabanov]: https://github.com/etehtsea
75
+ [Steve Sloan]: https://github.com/CodeMonkeySteve
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2011 Blake Carlson
1
+ Copyright (c) 2009-2015 Blake Carlson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,226 @@
1
+ Rack::GridFS
2
+ ============
3
+
4
+ Rack::GridFS is a Rack middleware for creating HTTP endpoints for files
5
+ stored in MongoDB's GridFS. You can configure a prefix string which
6
+ will be used to match the path of a request, and further look up GridFS
7
+ files based on either their `ObjectId` or `filename` field.
8
+
9
+ For example,
10
+
11
+ GET '/gridfs/someobjectid'
12
+
13
+ If the prefix is "gridfs", then the id will be be "someobjectid".
14
+
15
+ You can also use `Rack::GridFS::Endpoint` as a rack endpoint if you want to
16
+ handle routing another way.
17
+
18
+ ### Status ###
19
+
20
+ The library hasn't been updated for some time and is in the process of being
21
+ brought up to modern standards on the `master` branch. It does not yet work
22
+ with 2.x versions of the `mongo` driver gem, which means that you will not be
23
+ able to use it together with Mongoid 5.x (patches welcome if you need it faster
24
+ than we can deliver it). Since Mongoid 3.x and 4.x use the `moped` gem instead
25
+ of `mongo`, though, you may be able to use the current rack-gridfs release in
26
+ apps still using one of these older Mongoid versions. rack-gridfs should
27
+ support the latest 1.x `mongo` releases, [which support MongoDB 3.0][driver compat].
28
+
29
+ If your head is spinning, [this official blog post][driver 2.0] gives a good
30
+ breakdown of driver version history and the future.
31
+
32
+ [driver 2.0]: https://www.mongodb.com/blog/post/announcing-ruby-driver-20-rewrite
33
+ [driver compat]: https://docs.mongodb.org/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-mongodb-ruby
34
+
35
+ Features
36
+ --------
37
+
38
+ - Use as rack middleware or mount as a rack endpoint
39
+ - File lookup using a path or object id
40
+ - Chunked transfer encoding, keeps memory usage low
41
+ - Content-Type header set using 'mime-types' gem
42
+ - Last-Modified and Etag headers set automatically for conditional get support
43
+ - Cache-Control header support
44
+ - High availability when using replication sets
45
+
46
+ Installation
47
+ ------------
48
+
49
+ $ gem install rack-gridfs
50
+
51
+ Or in a Bundler project, add to your `Gemfile`:
52
+
53
+ ```ruby
54
+ gem 'rack-gridfs', '~> 0.4'
55
+ ```
56
+
57
+ Usage
58
+ -----
59
+
60
+ ```ruby
61
+ require 'rack/gridfs'
62
+
63
+ use Rack::GridFS, :prefix => 'gridfs',
64
+ :hostname => 'localhost',
65
+ :port => 27017,
66
+ :database => 'test'
67
+ ```
68
+
69
+ Options:
70
+
71
+ - `prefix`: a string used to match against incoming paths and route to through
72
+ the middleware. Default 'gridfs'.
73
+ - `lookup`: whether to look up a file based on `:id` or `:path` (example
74
+ below). Default is `:id`.
75
+ - `fs_name`: collection name for the file system, if not using the Mongo driver
76
+ default ("fs").
77
+
78
+ You must also specify MongoDB database details:
79
+
80
+ - `hostname`: the hostname/IP where the MongoDB server is running. Default 'localhost'.
81
+ - `port`: the port of the MongoDB server. Default 27017.
82
+ - `database`: the name of the MongoDB database to connect to.
83
+ - `username` and `password`: if you need to authenticate to MongoDB.
84
+
85
+ Alternatively you can pass in a `Mongo::DB` instance instead:
86
+
87
+ - `db`: `MongoMapper.database`, or `Mongoid.database` for example.
88
+
89
+ ### Simple Sinatra Example ###
90
+
91
+ ```ruby
92
+ require 'rubygems'
93
+ require 'sinatra'
94
+
95
+ require 'rack/gridfs'
96
+ use Rack::GridFS, :database => 'test', :prefix => 'gridfs'
97
+
98
+ get /.*/ do
99
+ "The URL did not match a file in GridFS."
100
+ end
101
+ ```
102
+
103
+ ### Usage with Rails 2 ###
104
+
105
+ To use `Rack::GridFS` in a Rails application, add it as middleware in
106
+ `application.rb` or `config/environments/*` with something like this:
107
+
108
+ ```ruby
109
+ config.middleware.insert_after Rack::Runtime, Rack::GridFS,
110
+ :prefix => 'uploads', :database => "my_app_#{Rails.env}"
111
+ ```
112
+
113
+ Run `rake middleware` to decide for yourself where to best place it in
114
+ the middleware stack for your app using [the Rails convenience methods],
115
+ taking into consideration that it can probably be near the top since it simply
116
+ returns a "static" file or a 404.
117
+
118
+ [the Rails convenience methods]: http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack,
119
+
120
+ ### Usage with Rails 3 ###
121
+
122
+ To use in Rails 3, you can insert into the middleware stack as above, or mount
123
+ the app directly in your routes (recommended). In `config/routes.rb`:
124
+
125
+ ```ruby
126
+ mount Rack::GridFS::Endpoint.new(:db => Mongoid.database), :at => "gridfs"
127
+ ```
128
+
129
+ This allows for much more straightforward and sensible configuration, if you do
130
+ not require other middleware in front of GridFS (Rack-based authorization, for
131
+ instance).
132
+
133
+ ### Path (filename) Lookup ###
134
+
135
+ The `:lookup => :path` option causes files to be looked up from the GridFS
136
+ store based on their `filename` field (which can be a full file path) rather than
137
+ `ObjectId` (requests still need to match the `prefix` you've set). This allows
138
+ you to find files based on essentially arbitrary URLs such as:
139
+
140
+ GET '/prefix/media/images/jane_avatar.jpg'
141
+
142
+ How filenames are set is specific to your application. We'll look at an example
143
+ with Carrierwave below.
144
+
145
+ **NOTE**: The Mongo Ruby driver will try to create an index on the `filename`
146
+ field for you automatically, but if you are using filename lookup you'll want to
147
+ double-check that it is created appropriately (on slaves only if you have a
148
+ master-slave architecture, etc.).
149
+
150
+ ### Carrierwave Example ###
151
+
152
+ Path lookup works well for usage with [Carrierwave]. As a minimal example with
153
+ Mongoid:
154
+
155
+ ```ruby
156
+ # config/initializers/carrierwave.rb
157
+ CarrierWave.configure do |config|
158
+ config.storage = :grid_fs
159
+ config.grid_fs_connection = Mongoid.database
160
+ config.grid_fs_access_url = "/uploads"
161
+ end
162
+
163
+ # app/uploaders/avatar_uploader.rb
164
+ class AvatarUploader < CarrierWave::Uploader::Base
165
+ # (Virtual) path where uploaded files will be stored, appended to the
166
+ # gridfs_access_url by methods used with view helpers
167
+ def store_dir
168
+ "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
169
+ end
170
+ end
171
+
172
+ # app/models/user.rb
173
+ class User
174
+ include Mongoid::Document
175
+ mount_uploader :avatar, AvatarUploader
176
+ end
177
+ ```
178
+
179
+ ```eruby
180
+ <%# app/views/user/show.html.erb %>
181
+ <%= image_tag(@user.avatar.url) if @user.avatar? %>
182
+ ```
183
+
184
+ This will result in URL paths like `/uploads/user/avatar/4d250d04a8f41c0a31000006/original_filename.jpg`
185
+ being generated for the view helpers, and Carrierwave will store
186
+ `user/avatar/4d250d04a8f41c0a31000006/original_filename.jpg` as the
187
+ `filename` in GridFS. Thus, you can configure `Rack::GridFS` to serve
188
+ these files as such:
189
+
190
+ ```ruby
191
+ config.middleware.insert_after Rack::Runtime, Rack::GridFS,
192
+ :prefix => 'uploads', :lookup => :path, :database => "my_app_#{Rails.env}"
193
+ ```
194
+
195
+ [Carrierwave]: https://github.com/jnicklas/carrierwave.
196
+
197
+ Ruby Version and Mongo Driver Compatibility Notes
198
+ -------------------------------------------------
199
+
200
+ If for some reason you need support for ancient versions of the `mongo` driver
201
+ prior to v1.2, these were supported in rack-gridfs 0.3.0 and below. 0.4.x
202
+ supports `mongo` 1.2+ which made substantial changes to the earlier GridFS
203
+ API.
204
+
205
+ Support for Ruby 1.8 is no longer being tested and will be dropped in the next
206
+ version that supports `mongo` 2.x (the driver itself officially drops 1.8
207
+ support). It was supported up to rack-gridfs gem release/git tag v0.4.2.
208
+
209
+ Development and Contributing
210
+ ----------------------------
211
+
212
+ Running the project and unit tests in development follows typical procedure for
213
+ a Ruby project:
214
+
215
+ $ git clone https://github.com/skinandbones/rack-gridfs.git
216
+ $ cd rack-gridfs
217
+ $ bundle install
218
+ $ bundle exec rake test
219
+
220
+ Note that the test suite expects that you have MongoDB running locally on the
221
+ default port and will use a database called `test`.
222
+
223
+ Copyright
224
+ ---------
225
+
226
+ Copyright (c) 2010-2015 Blake Carlson. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,13 +1,19 @@
1
1
  require 'bundler/setup'
2
+ require 'rake/testtask'
3
+ require 'yard'
4
+
5
+ require File.expand_path("../lib/rack/gridfs/version", __FILE__)
6
+
2
7
  Bundler::GemHelper.install_tasks
3
8
 
4
- require 'rake/testtask'
5
9
  Rake::TestTask.new(:test) do |test|
6
10
  test.libs << 'lib' << 'test'
7
11
  test.pattern = 'test/**/*_test.rb'
8
12
  test.verbose = true
9
13
  end
10
14
 
15
+ task :default => :test
16
+
11
17
  begin
12
18
  require 'rcov/rcovtask'
13
19
  Rcov::RcovTask.new do |test|
@@ -22,14 +28,7 @@ rescue LoadError
22
28
  end
23
29
  end
24
30
 
25
- task :default => :test
26
-
27
- require 'rake/rdoctask'
28
- Rake::RDocTask.new do |rdoc|
29
- require File.expand_path("../lib/rack/gridfs/version", __FILE__)
30
-
31
- rdoc.rdoc_dir = 'rdoc'
32
- rdoc.title = "Rack::GridFS #{Rack::GridFS::VERSION}"
33
- rdoc.rdoc_files.include(%w[ README* CHANGES* ])
34
- rdoc.rdoc_files.include('lib/**/*.rb')
31
+ YARD::Rake::YardocTask.new do |t|
32
+ t.name = 'doc'
33
+ t.files = ['lib/**/*.rb']
35
34
  end
@@ -0,0 +1 @@
1
+ require 'rack/gridfs'
@@ -39,9 +39,11 @@ module Rack
39
39
 
40
40
  # TODO: doc explanation/example of custom mapper
41
41
  def normalize_options(options)
42
+ options = options.dup
43
+
42
44
  options.tap do |opts|
43
45
  opts[:prefix] ||= "gridfs"
44
- opts[:prefix].gsub!(/^\//, '')
46
+ opts[:prefix] = options[:prefix].gsub(/^\//, '')
45
47
  opts[:mapper] ||= lambda { |path| %r!^/#{options[:prefix]}/(.+)!.match(path)[1] }
46
48
  end
47
49
  end
@@ -7,9 +7,10 @@ module Rack
7
7
  def initialize(options = {})
8
8
  @options = default_options.merge(options)
9
9
 
10
- @db = @options[:db]
11
- @lookup = @options[:lookup]
12
- @mapper = @options[:mapper]
10
+ @db = @options[:db]
11
+ @lookup = @options[:lookup]
12
+ @mapper = @options[:mapper]
13
+ @fs_name = @options[:fs_name]
13
14
  end
14
15
 
15
16
  def call(env)
@@ -31,7 +32,8 @@ module Rack
31
32
  def default_options
32
33
  {
33
34
  :lookup => :id,
34
- :mapper => lambda { |path| %r!/(.+)!.match(path)[1] }
35
+ :mapper => lambda { |path| %r!/(.+)!.match(path)[1] },
36
+ :fs_name => Mongo::Grid::DEFAULT_FS_NAME
35
37
  }
36
38
  end
37
39
 
@@ -62,10 +64,10 @@ module Rack
62
64
  def find_file(id_or_path)
63
65
  case @lookup.to_sym
64
66
  when :id
65
- Mongo::Grid.new(db).get(BSON::ObjectId.from_string(id_or_path))
67
+ Mongo::Grid.new(db, @fs_name).get(BSON::ObjectId.from_string(id_or_path))
66
68
  when :path
67
69
  path = CGI::unescape(id_or_path)
68
- Mongo::GridFileSystem.new(db).open(path, "r")
70
+ Mongo::GridFileSystem.new(db, @fs_name).open(path, "r")
69
71
  end
70
72
  end
71
73
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class GridFS
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,197 +1,215 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-gridfs
3
- version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Blake Carlson
8
+ - Ches Martin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-27 00:00:00 +07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
12
+ date: 2015-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bson
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.2'
21
+ type: :runtime
31
22
  prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.2'
28
+ - !ruby/object:Gem::Dependency
32
29
  name: rack
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
33
35
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 11
42
- segments:
43
- - 1
44
- - 2
45
- version: "1.2"
46
36
  prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
47
43
  name: mongo
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.2'
48
49
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
50
  prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.2'
56
+ - !ruby/object:Gem::Dependency
61
57
  name: mime-types
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
62
63
  type: :runtime
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- requirement: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
68
74
  - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 23
71
- segments:
72
- - 1
73
- - 0
74
- - 0
75
+ - !ruby/object:Gem::Version
75
76
  version: 1.0.0
77
+ type: :development
76
78
  prerelease: false
77
- name: bundler
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.0.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '5.8'
78
91
  type: :development
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- requirement: &id005 !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - "="
85
- - !ruby/object:Gem::Version
86
- hash: 35
87
- segments:
88
- - 0
89
- - 9
90
- - 12
91
- version: 0.9.12
92
92
  prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '5.8'
98
+ - !ruby/object:Gem::Dependency
93
99
  name: mocha
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.1'
94
105
  type: :development
95
- version_requirements: *id005
96
- - !ruby/object:Gem::Dependency
97
- requirement: &id006 !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
106
106
  prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.1'
112
+ - !ruby/object:Gem::Dependency
107
113
  name: rack-test
108
- type: :development
109
- version_requirements: *id006
110
- - !ruby/object:Gem::Dependency
111
- requirement: &id007 !ruby/object:Gem::Requirement
112
- none: false
113
- requirements:
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
114
116
  - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 3
117
- segments:
118
- - 0
119
- version: "0"
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
120
  prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
121
127
  name: rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
122
133
  type: :development
123
- version_requirements: *id007
124
- - !ruby/object:Gem::Dependency
125
- requirement: &id008 !ruby/object:Gem::Requirement
126
- none: false
127
- requirements:
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
128
137
  - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: shoulda-context
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1.2'
147
+ type: :development
134
148
  prerelease: false
135
- name: shoulda
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '1.2'
154
+ - !ruby/object:Gem::Dependency
155
+ name: yard
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
136
161
  type: :development
137
- version_requirements: *id008
138
- description: Rack middleware for creating HTTP endpoints for files stored in MongoDB's GridFS
139
- email:
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: Rack middleware for creating HTTP endpoints for files stored in MongoDB's
169
+ GridFS
170
+ email:
140
171
  - blake@coin-operated.net
172
+ - ches@whiskeyandgrits.net
141
173
  executables: []
142
-
143
174
  extensions: []
144
-
145
- extra_rdoc_files:
146
- - CHANGES.rdoc
175
+ extra_rdoc_files:
176
+ - CHANGES.md
177
+ - LICENSE
178
+ - README.md
179
+ files:
180
+ - CHANGES.md
147
181
  - LICENSE
148
- - README.rdoc
149
- files:
182
+ - README.md
183
+ - Rakefile
184
+ - lib/rack-gridfs.rb
185
+ - lib/rack/gridfs.rb
186
+ - lib/rack/gridfs/endpoint.rb
150
187
  - lib/rack/gridfs/endpoint/base.rb
151
188
  - lib/rack/gridfs/endpoint/caching.rb
152
189
  - lib/rack/gridfs/endpoint/connection.rb
153
- - lib/rack/gridfs/endpoint.rb
154
190
  - lib/rack/gridfs/version.rb
155
- - lib/rack/gridfs.rb
156
- - LICENSE
157
- - README.rdoc
158
- - Rakefile
159
- - CHANGES.rdoc
160
- has_rdoc: true
161
191
  homepage: http://github.com/skinandbones/rack-gridfs
162
192
  licenses: []
163
-
193
+ metadata: {}
164
194
  post_install_message:
165
195
  rdoc_options: []
166
-
167
- require_paths:
196
+ require_paths:
168
197
  - lib
169
- required_ruby_version: !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
172
200
  - - ">="
173
- - !ruby/object:Gem::Version
174
- hash: 3
175
- segments:
176
- - 0
177
- version: "0"
178
- required_rubygems_version: !ruby/object:Gem::Requirement
179
- none: false
180
- requirements:
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
181
205
  - - ">="
182
- - !ruby/object:Gem::Version
183
- hash: 23
184
- segments:
185
- - 1
186
- - 3
187
- - 6
206
+ - !ruby/object:Gem::Version
188
207
  version: 1.3.6
189
208
  requirements: []
190
-
191
209
  rubyforge_project: rack-gridfs
192
- rubygems_version: 1.5.2
210
+ rubygems_version: 2.4.5.1
193
211
  signing_key:
194
- specification_version: 3
212
+ specification_version: 4
195
213
  summary: Serve MongoDB GridFS files from Rack
196
214
  test_files: []
197
-
215
+ has_rdoc:
@@ -1,41 +0,0 @@
1
- == CHANGE LOG
2
-
3
- === 0.4.1 / June 26, 2011
4
-
5
- {full commit log}[https://github.com/skinandbones/rack-gridfs/compare/v0.4.0...v0.4.1]
6
-
7
- ==== Bug Fixes
8
-
9
- - URL-decode before filename lookup so that non-ASCII filenames are handled
10
- correctly (Konstantin Shabanov)
11
-
12
-
13
- === 0.4.0 / May 12, 2011
14
-
15
- Major refactoring and loads of new features! Thanks to {Ben Marini}[https://github.com/bmarini]
16
- for his substantial contributions to this release.
17
-
18
- {full commit log}[https://github.com/skinandbones/rack-gridfs/compare/v0.2.0...v0.4.0]
19
-
20
- ==== Features
21
-
22
- - Allow configuration of MongoDB authentication (Steve Sloan)
23
- - Allow option to look up objects by GridFS filename instead of +ObjectId+
24
- (SHIBATA Hiroshi)
25
- - Return iterable GridIO object instead of file contents, so Rack can stream in
26
- chunks (Ches Martin)
27
- - <tt>Rack::GridFS::Endpoint</tt>: support for mounting as a Rack endpoint in
28
- addition to middleware (Ben Marini)
29
- - Cache headers: set <tt>Last-Modified</tt> and +Etag+ so that
30
- <tt>Rack::ConditionalGet</tt> sends 304s. +expires+ option to set
31
- <tt>Cache-Control</tt> (Alexander Gräfe & Ben Marini)
32
- - <tt>mime-types</tt> dependency so GridFS lib can determine content types
33
- (Ben Marini)
34
- - You can now pass a <tt>Mongo::DB</tt> instance instead of discrete database
35
- configuration parameters. Connections are retried so we take advantage of a
36
- +ReplSetConnection+ in high-availability architectures (Ben Marini)
37
-
38
- ==== Bug Fixes
39
-
40
- - <tt>BSON::ObjectID</tt> renamed to +ObjectId+, and other changes supporting
41
- current versions of Mongo libraries
@@ -1,150 +0,0 @@
1
- = Rack::GridFS
2
-
3
- Rack:GridFS is a Rack middleware for creating HTTP endpoints for files
4
- stored in MongoDB's GridFS. You can configure a prefix string which
5
- will be used to match the path of a request, and further look up GridFS
6
- files based on either their +ObjectId+ or +filename+ field.
7
-
8
- For example,
9
-
10
- GET '/gridfs/someobjectid'
11
-
12
- If the prefix is "gridfs", then the id will be be "someobjectid".
13
-
14
- You can also use Rack::GridFS::Endpoint as a rack endpoint if you want to
15
- handle routing another way
16
-
17
- == Mongo Driver Compatibility Notes
18
-
19
- This version is currently based on mongo-1.2+. As there were significant changes
20
- to the GridFS API prior to v1.0, you may have luck with the git-tagged version
21
- 0.2.0 of this library with earlier versions of the driver.
22
-
23
- == Installation
24
-
25
- gem install rack-gridfs
26
-
27
- == Features
28
- - Use as rack middleware or mount as a rack endpoint
29
- - File lookup using a path or object id
30
- - Chunked transfer encoding, keeps memory usage low
31
- - Content-Type header set using 'mime-types' gem
32
- - Last-Modified and Etag headers set automatically for conditional get support
33
- - Cache-Control header support
34
- - High availability when using replication sets
35
-
36
- == Usage
37
-
38
- require 'rack/gridfs'
39
- use Rack::GridFS, :prefix => 'gridfs', :hostname => 'localhost', :port => 27017, :database => 'test'
40
-
41
- Options:
42
- - +prefix+: a string used to match against incoming paths and route to through
43
- the middleware. Default 'gridfs'.
44
- - +lookup+: whether to look up a file based on <tt>:id</tt> or <tt>:path</tt>
45
- (example below). Default is <tt>:id</tt>.
46
-
47
- You must also specify MongoDB database details:
48
- - +hostname+: the hostname/IP where the MongoDB server is running. Default 'localhost'.
49
- - +port+: the port of the MongoDB server. Default 27017.
50
- - +database+: the name of the MongoDB database to connect to.
51
- - +username+ and +password+: if you need to authenticate to MongoDB.
52
-
53
- Alternatively you can pass in a <tt>Mongo::DB</tt> instance instead:
54
- - +db+: MongoMapper.database, or Mongoid.database for example.
55
-
56
- === Simple Sinatra Example
57
-
58
- require 'rubygems'
59
- require 'sinatra'
60
-
61
- require 'rack/gridfs'
62
- use Rack::GridFS, :database => 'test', :prefix => 'gridfs'
63
-
64
- get /.*/ do
65
- "The URL did not match a file in GridFS."
66
- end
67
-
68
- === Usage with Rails 2
69
-
70
- To use <tt>Rack::GridFS</tt> in a Rails application, add it as middleware in
71
- <tt>application.rb</tt> or <tt>config/environments/*</tt>with something like this:
72
-
73
- config.middleware.insert_after Rack::Runtime, Rack::GridFS,
74
- :prefix => 'uploads', :database => "my_app_#{Rails.env}"
75
-
76
- Run <tt>rake middleware</tt> to decide for yourself where to best place it in
77
- the middleware stack for your app using {the Rails convenience methods}[http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack],
78
- taking into consideration that it can probably be near the top since it simply
79
- returns a "static" file or a 404.
80
-
81
- === Usage with Rails 3
82
-
83
- To use in Rails 3, you can insert into the middleware stack as above, or mount
84
- the app directly in your routes (recommended). In <tt>config/routes.rb</tt>:
85
-
86
- mount Rack::GridFS::Endpoint.new(:db => Mongoid.database), :at => "gridfs"
87
-
88
- This allows for much more straightforward and sensible configuration, if you do
89
- not require other middleware in front of GridFS (Rack-based authorization, for
90
- instance).
91
-
92
- === Path (filename) Lookup
93
-
94
- The <tt>:lookup => :path</tt> option causes files to be looked up from the GridFS
95
- store based on their +filename+ field (which can be a full file path) rather than
96
- +ObjectId+ (requests still need to match the +prefix+ you've set). This allows
97
- you to find files based on essentially arbitrary URLs such as:
98
-
99
- GET '/prefix/media/images/jane_avatar.jpg'
100
-
101
- How filenames are set is specific to your application. We'll look at an example
102
- with Carrierwave below.
103
-
104
- *NOTE*: The Mongo Ruby driver will try to create an index on the +filename+
105
- field for you automatically, but if you are using filename lookup you'll want to
106
- double-check that it is created appropriately (on slaves only if you have a
107
- master-slave architecture, etc.).
108
-
109
- === Carrierwave Example
110
-
111
- Path lookup works well for usage with Carrierwave[https://github.com/jnicklas/carrierwave].
112
- As a minimal example with Mongoid:
113
-
114
- # config/initializers/carrierwave.rb
115
- CarrierWave.configure do |config|
116
- config.storage = :grid_fs
117
- config.grid_fs_connection = Mongoid.database
118
- config.grid_fs_access_url = "/uploads"
119
- end
120
-
121
- # app/uploaders/avatar_uploader.rb
122
- class AvatarUploader < CarrierWave::Uploader::Base
123
- # (Virtual) path where uploaded files will be stored, appended to the
124
- # gridfs_access_url by methods used with view helpers
125
- def store_dir
126
- "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
127
- end
128
- end
129
-
130
- # app/models/user.rb
131
- class User
132
- include Mongoid::Document
133
- mount_uploader :avatar, AvatarUploader
134
- end
135
-
136
- # app/views/user/show.html.erb
137
- <%= image_tag(@user.avatar.url) if @user.avatar? %>
138
-
139
- This will result in URL paths like <tt>/uploads/user/avatar/4d250d04a8f41c0a31000006/original_filename.jpg</tt>
140
- being generated for the view helpers, and Carrierwave will store
141
- <tt>user/avatar/4d250d04a8f41c0a31000006/original_filename.jpg</tt> as the
142
- +filename+ in GridFS. Thus, you can configure <tt>Rack::GridFS</tt> to serve
143
- these files as such:
144
-
145
- config.middleware.insert_after Rack::Runtime, Rack::GridFS,
146
- :prefix => 'uploads', :lookup => :path, :database => "my_app_#{Rails.env}"
147
-
148
- == Copyright
149
-
150
- Copyright (c) 2010-2011 Blake Carlson. See LICENSE for details.