carrierwave-serializable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/carrierwave-serializable.gemspec +22 -0
- data/lib/carrierwave-serializable/orm/activerecord.rb +59 -0
- data/lib/carrierwave-serializable/version.rb +5 -0
- data/lib/carrierwave-serializable.rb +5 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tima Maslyuchenko
|
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,31 @@
|
|
1
|
+
# Carrierwave::Serializable
|
2
|
+
|
3
|
+
Carrierwave plugin that allow mount uploader to serialized field
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-serializable'
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
$ gem install carrierwave-serializable
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
If you need mount uploader to serialized field, set `serialize_to` option
|
18
|
+
to serialized field where you want to store your uplaoder.
|
19
|
+
|
20
|
+
class User < ActiveRecord::Base
|
21
|
+
serialize :documents, Hash
|
22
|
+
mount_uploader :document1, DocumentUploader, serialize_to: :documents
|
23
|
+
end
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave-serializable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "carrierwave-serializable"
|
8
|
+
gem.version = CarrierWave::Serializable::VERSION
|
9
|
+
gem.authors = ["Tima Maslyuchenko"]
|
10
|
+
gem.email = ["insside@gmail.com"]
|
11
|
+
gem.description = %q{Carrierwave plugin that allow mount uploader to serialized field}
|
12
|
+
gem.summary = %q{Carrierwave plugin that allow mount uploader to serialized field}
|
13
|
+
gem.homepage = "https://github.com/timsly/carrierwave-serializable"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'carrierwave'
|
21
|
+
gem.add_dependency 'activesupport'
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "carrierwave/orm/activerecord"
|
4
|
+
|
5
|
+
module CarrierWave
|
6
|
+
module ActiveRecord
|
7
|
+
module Serializable
|
8
|
+
def serialized_uploaders
|
9
|
+
@serialized_uploaders ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialized_uploader?(column)
|
13
|
+
serialized_uploaders.key?(column) && serialized_attributes.key?(serialized_uploaders[column].to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# See +CarrierWave::Mount#mount_uploader+ for documentation
|
18
|
+
#
|
19
|
+
def mount_uploader(column, uploader=nil, options={}, &block)
|
20
|
+
super
|
21
|
+
|
22
|
+
serialize_to = options.delete :serialize_to
|
23
|
+
if serialize_to
|
24
|
+
serialized_uploaders[column] = serialize_to
|
25
|
+
class_eval <<-RUBY, __FILE__, __LINE__+1
|
26
|
+
def #{column}_will_change!
|
27
|
+
#{serialize_to}_will_change!
|
28
|
+
@#{column}_changed = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def #{column}_changed?
|
32
|
+
@#{column}_changed
|
33
|
+
end
|
34
|
+
RUBY
|
35
|
+
end
|
36
|
+
|
37
|
+
class_eval <<-RUBY, __FILE__, __LINE__+1
|
38
|
+
def write_uploader(column, identifier)
|
39
|
+
if self.class.serialized_uploader?(column)
|
40
|
+
serialized_field = self.send self.class.serialized_uploaders[column]
|
41
|
+
serialized_field[column.to_s] = identifier
|
42
|
+
else
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def read_uploader(column)
|
48
|
+
if self.class.serialized_uploader?(column)
|
49
|
+
serialized_field = self.send self.class.serialized_uploaders[column]
|
50
|
+
serialized_field[column.to_s]
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
RUBY
|
56
|
+
end
|
57
|
+
end # Serializable
|
58
|
+
end # ActiveRecord
|
59
|
+
end # CarrierWave
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-serializable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tima Maslyuchenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: carrierwave
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Carrierwave plugin that allow mount uploader to serialized field
|
47
|
+
email:
|
48
|
+
- insside@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- carrierwave-serializable.gemspec
|
59
|
+
- lib/carrierwave-serializable.rb
|
60
|
+
- lib/carrierwave-serializable/orm/activerecord.rb
|
61
|
+
- lib/carrierwave-serializable/version.rb
|
62
|
+
homepage: https://github.com/timsly/carrierwave-serializable
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.23
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Carrierwave plugin that allow mount uploader to serialized field
|
86
|
+
test_files: []
|