carrierwave-hex-prefix-for-file-storage 0.0.1
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.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +63 -0
- data/lib/carrierwave-hex-prefix-for-file-storage.rb +19 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed34f82b2cf8085d4a3e41070d038fc99f839634
|
4
|
+
data.tar.gz: d9ea3e422629a6a4107037f8837a3cc3545969d5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e128fa9e19af5271a1a806d60b65790b026029c90c0cbcb8c85b49c5cfb4575806005b6b75baef49ff0017d81032751efca41bf964150579426a71e324c0d403
|
7
|
+
data.tar.gz: 0d431e49b2af1bd308105a8171d9f77356d3fd75df11dba3fedb53f7cb18ccbde2a17ff2f36300b3af3af2ff1aaf05128951311ad769fad55e10fcbc3c2fc48a
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright 2014 Marcin Lewandowski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
17
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
18
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
19
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
This is a simple Ryby gem that just enscapsulates directory naming scheme for [carrierwave's](https://github.com/carrierwaveuploader/carrierwave) file storage, enabling creation of directory structure that will be efficient and survive subdirectories limit.
|
4
|
+
|
5
|
+
|
6
|
+
## Problem
|
7
|
+
|
8
|
+
If you have plenty of attachments you can encounter slowdowns or OS will reject creating next subdirectory at some point.
|
9
|
+
|
10
|
+
It is due to the fact that some filesystems have limit of subdirectories (for example: 64000 in ext4, until you enable the file system feature flag dir_nlink). Moreover, having a flat subdirectories structure can be suboptimal.
|
11
|
+
|
12
|
+
## Solution
|
13
|
+
|
14
|
+
Create directory structure of following syntax:
|
15
|
+
|
16
|
+
(ROOT_PATH)/(model class)/(mounted as)/(record's ID in hex split into groups of max 3 characters)/(file name)
|
17
|
+
|
18
|
+
For example:
|
19
|
+
|
20
|
+
/home/myrailsapp/public/system/User/Avatar/af7/233/1a3/12/whatever.mp3
|
21
|
+
|
22
|
+
|
23
|
+
# Installation
|
24
|
+
|
25
|
+
Add to your Gemfile:
|
26
|
+
|
27
|
+
gem "carrierwave-hex-prefix-for-file-storage"
|
28
|
+
|
29
|
+
and then type:
|
30
|
+
|
31
|
+
bundle install
|
32
|
+
|
33
|
+
Then include it in your Uploader:
|
34
|
+
|
35
|
+
class SourceBodyUploader < CarrierWave::Uploader::Base
|
36
|
+
include CarrierWave::Uploader::HexPrefixForFileStorage
|
37
|
+
|
38
|
+
storage :file
|
39
|
+
|
40
|
+
def store_dir
|
41
|
+
store_dir_with_hex_prefix
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Optionally, you can pass a parameter to `store_dir_with_hex_prefix` in order to change root path (by default it is `RAILS_ROOT/public/system`):
|
46
|
+
|
47
|
+
class SourceBodyUploader < CarrierWave::Uploader::Base
|
48
|
+
include CarrierWave::Uploader::HexPrefixForFileStorage
|
49
|
+
|
50
|
+
storage :file
|
51
|
+
|
52
|
+
def store_dir
|
53
|
+
store_dir_with_hex_prefix Rails.root.join("my_directory")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Changelog
|
58
|
+
|
59
|
+
0.0.1 - Initial release
|
60
|
+
|
61
|
+
# License
|
62
|
+
|
63
|
+
MIT
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Uploader
|
3
|
+
module HexPrefixForFileStorage
|
4
|
+
def store_dir_with_hex_prefix(root_path = nil)
|
5
|
+
if root_path.nil?
|
6
|
+
path = [ Rails.root.join("public", "system").to_s ]
|
7
|
+
else
|
8
|
+
path = [ root_path.to_s ]
|
9
|
+
end
|
10
|
+
|
11
|
+
path << model.class.to_s.underscore
|
12
|
+
path << mounted_as.to_s
|
13
|
+
model.id.to_s(16).split("").each_slice(3) { |x| path << x.join }
|
14
|
+
|
15
|
+
File.join *path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-hex-prefix-for-file-storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcin Lewandowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Enscapsulates directory naming scheme for carrierwave's file storage,
|
28
|
+
enabling creation of directory structure that will be efficient and survive subdirs
|
29
|
+
limit.
|
30
|
+
email:
|
31
|
+
- marcin@saepia.net
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/carrierwave-hex-prefix-for-file-storage.rb
|
39
|
+
homepage: http://github.com/mspanc/carrierwave-hex-prefix-for-file-storage
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.2.2
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Creates efficient directory structure for carrierwave attachments
|
62
|
+
test_files: []
|