carrierwave-data 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/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +2 -0
- data/carrierwave-data.gemspec +22 -0
- data/lib/carrierwave-data.rb +13 -0
- data/lib/carrierwave-data/orm/activerecord.rb +42 -0
- data/lib/carrierwave-data/version.rb +5 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ed1e109057975aa836d2884949bcd32ef2e2293
|
4
|
+
data.tar.gz: 3b20c00e2c2f218f34ee328ada9acdf2fe71510d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 973d34865f9aede5624332f2b33815b78c527653cf52ba69e21e1f244759427b6d501861eef38fe9b17dc0755ccfa2aac3546562d1e89f769240b8418a78c396
|
7
|
+
data.tar.gz: 084c9b8ab5b3378ce430ebd01f10d7d52b9326283ae68862505217d95b4047fb49537a932a104b61ca16e0cf2861ef7e9a1936d18cd1324bfdb89b0a0d64079d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ramy Aboul Naga
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# CarrierWave::Data
|
2
|
+
|
3
|
+
Allows [CarrierWave](https://github.com/carrierwaveuploader/carrierwave) to process Base64 encoded file uploads.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'carrierwave-data'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install carrierwave-data
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Assuming you have a `User` model with a `UserAvatarUploader` mounted on an `avatar` attribute.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class User < ActiveRecord::Base
|
27
|
+
mount_uploader :avatar, UserAvatarUploader
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
A `User`'s `avatar` can be set using a Base64 encoded string, as follows.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
user = User.new
|
35
|
+
user.avatar_data = 'iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABuBvAAAABGdBTUE...kJggg=='
|
36
|
+
user.save
|
37
|
+
|
38
|
+
user.avatar? # => true
|
39
|
+
user.avatar # => #<UserAvatarUploader:0x007f9575fddc18 @model=#<User id: 1, avatar: "2d45cced04356fcfac278ef06f76d567">, @mounted_as=:avatar, ...>
|
40
|
+
````
|
41
|
+
|
42
|
+
## Customizations
|
43
|
+
|
44
|
+
By default, the filename of the decoded uploaded file is set to a random hex string, using `SecureRandom.hex`. To customize this behaviour, override the `decoded_#{mounted_as}_filename` method on your model.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class User < ActiveRecord::Base
|
48
|
+
mount_uploader :avatar, UserAvatarUploader
|
49
|
+
|
50
|
+
def decoded_avatar_filename
|
51
|
+
'avatar'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
You can also customize the extension of the decoded uploaded file by overriding the `decoded_#{mounted_as}_extension` method. By default, no extension is set.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class User < ActiveRecord::Base
|
60
|
+
mount_uploader :avatar, UserAvatarUploader
|
61
|
+
|
62
|
+
def decoded_avatar_extension
|
63
|
+
:png
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it ( https://github.com/RaMin0/carrierwave-data/fork )
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave-data/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'carrierwave-data'
|
8
|
+
spec.version = CarrierWave::Data::VERSION
|
9
|
+
spec.authors = ['Ramy Aboul Naga']
|
10
|
+
spec.email = ['ramy.naga@gmail.com']
|
11
|
+
spec.summary = %q{Allows carrierwave to process Base64 encoded file uploads.}
|
12
|
+
spec.description = %q{Allows carrierwave to process Base64 encoded file uploads by providing a `#{mounted_as}_data=` method that accepts Base64 encoded strings and sets the #{mounted_as} column accordingly.}
|
13
|
+
spec.homepage = 'https://github.com/RaMin0/carrierwave-data'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'carrierwave', '~> 0'
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
if defined?(Rails)
|
2
|
+
module CarrierWave
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer 'carrierwave-data.active_record' do
|
5
|
+
ActiveSupport.on_load :active_record do
|
6
|
+
require 'carrierwave-data/orm/activerecord'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'carrierwave-data/version'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module ActiveRecord
|
5
|
+
module Data
|
6
|
+
# See +CarrierWave::Mount#mount_uploader+ for documentation
|
7
|
+
def mount_uploader(column, uploader = nil, options = {}, &block)
|
8
|
+
super
|
9
|
+
|
10
|
+
attr_writer :"#{column}_data"
|
11
|
+
|
12
|
+
before_validation :"decode_#{column}_data", if: :"#{column}_data?"
|
13
|
+
|
14
|
+
class_eval <<-RUBY, __FILE__, __LINE__+1
|
15
|
+
def #{column}_data?
|
16
|
+
!!@#{column}_data
|
17
|
+
end
|
18
|
+
|
19
|
+
def decoded_#{column}_filename
|
20
|
+
SecureRandom.hex
|
21
|
+
end
|
22
|
+
|
23
|
+
def decoded_#{column}_extension
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def decode_#{column}_data
|
29
|
+
file = Tempfile.new('carrierwave-data')
|
30
|
+
file.binmode
|
31
|
+
file.write(Base64.decode64(@#{column}_data))
|
32
|
+
|
33
|
+
filename = [decoded_#{column}_filename, decoded_#{column}_extension].compact.join('.')
|
34
|
+
self.#{column} = ActionDispatch::Http::UploadedFile.new(tempfile: file, filename: filename)
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
end # Data
|
39
|
+
end # ActiveRecord
|
40
|
+
end # CarrierWave
|
41
|
+
|
42
|
+
ActiveRecord::Base.extend CarrierWave::ActiveRecord::Data
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramy Aboul Naga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-18 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: 'Allows carrierwave to process Base64 encoded file uploads by providing
|
28
|
+
a `#{mounted_as}_data=` method that accepts Base64 encoded strings and sets the
|
29
|
+
#{mounted_as} column accordingly.'
|
30
|
+
email:
|
31
|
+
- ramy.naga@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- carrierwave-data.gemspec
|
42
|
+
- lib/carrierwave-data.rb
|
43
|
+
- lib/carrierwave-data/orm/activerecord.rb
|
44
|
+
- lib/carrierwave-data/version.rb
|
45
|
+
homepage: https://github.com/RaMin0/carrierwave-data
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.4.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Allows carrierwave to process Base64 encoded file uploads.
|
69
|
+
test_files: []
|