essay-carrierwave 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +14 -0
- data/essay-carrierwave.gemspec +21 -0
- data/lib/essay-carrierwave/attribute.rb +59 -0
- data/lib/essay-carrierwave/model.rb +140 -0
- data/lib/essay-carrierwave.rb +7 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f89ed883ff13eac1fb3e60b21b2080358db8a5fd
|
4
|
+
data.tar.gz: a06588187ed94cb1ebd05b55271aaa7d21718dba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd7e6ae01298117ffc5c3438168777f41d171d9e83d70684145322a2d43cbebd1efe80c2ec8e4f979260de4a1ac2db68663a2dd384a4810c048d4e104c381f02
|
7
|
+
data.tar.gz: 24dbcc10e628c4711276edf30141053b581c45f384e7dfcec324fe6dfd9e2156a375ed678705a69988ea9d6271204485e458f1069c3a67619c4548e4679b3d74
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Yaroslav Konoplov
|
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,14 @@
|
|
1
|
+
```ruby
|
2
|
+
class Article < ActiveRecord::Base
|
3
|
+
mount_uploader :poster, PosterUploader
|
4
|
+
end
|
5
|
+
|
6
|
+
Article.features.has_carrierwave_uploaders? # => true
|
7
|
+
Article.attribute_features[:poster].has_carrierwave_uploader? # => true
|
8
|
+
Article.attribute_features[:poster].carrierwave.mounted_on # => :poster
|
9
|
+
```
|
10
|
+
|
11
|
+
## Gemfile
|
12
|
+
```ruby
|
13
|
+
gem 'essay-carrierwave', github: 'yivo/essay-carrierwave'
|
14
|
+
```
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'essay-carrierwave'
|
6
|
+
s.version = '1.0.1'
|
7
|
+
s.authors = ['Yaroslav Konoplov']
|
8
|
+
s.email = ['eahome00@gmail.com']
|
9
|
+
s.summary = 'essay-carrierwave'
|
10
|
+
s.description = 'essay-carrierwave'
|
11
|
+
s.homepage = 'http://github.com/yivo/essay-carrierwave'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.executables = `git ls-files -z -- bin/*`.split("\x0").map{ |f| File.basename(f) }
|
15
|
+
s.files = `git ls-files -z`.split("\x0")
|
16
|
+
s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'carrierwave', '>= 0'
|
20
|
+
s.add_dependency 'essay', '~> 1.0'
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Essay::AttributeFeatures
|
5
|
+
def has_uploader?
|
6
|
+
has_carrierwave_uploader?
|
7
|
+
end
|
8
|
+
|
9
|
+
def has_carrierwave_uploader?
|
10
|
+
!!model_features.with(:carrierwave) { |cw| cw.uploader_for(this_attribute.name) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def carrierwave
|
14
|
+
@carrierwave || if has_carrierwave_uploader?
|
15
|
+
@carrierwave = HasCarrierWaveUploader.new(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
serialize do
|
20
|
+
{
|
21
|
+
has_carrierwave_uploader: has_carrierwave_uploader?,
|
22
|
+
carrierwave: carrierwave.try(:to_hash)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
class HasCarrierWaveUploader < Base
|
27
|
+
# class Article
|
28
|
+
# mount_uploader :poster, PosterUploader
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# Article.attribute_features[:poster].carrierwave.uploader => PosterUploader
|
32
|
+
#
|
33
|
+
def uploader
|
34
|
+
top_feature.uploader_for(this_attribute.name)
|
35
|
+
end
|
36
|
+
|
37
|
+
# class Article
|
38
|
+
# mount_uploader :poster, PosterUploader
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# Article.attribute_features[:poster].carrierwave.mounted_as => :poster
|
42
|
+
#
|
43
|
+
def mounted_as
|
44
|
+
top_feature.accessor_for(this_attribute.name)
|
45
|
+
end
|
46
|
+
|
47
|
+
serialize do
|
48
|
+
{
|
49
|
+
uploader: uploader.name,
|
50
|
+
mounted_as: mounted_as
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def top_feature
|
56
|
+
model_features.carrierwave
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Essay::ModelFeatures
|
5
|
+
def has_uploaders?
|
6
|
+
has_carrierwave_uploaders?
|
7
|
+
end
|
8
|
+
|
9
|
+
def has_carrierwave_uploaders?
|
10
|
+
has_own_carrierwave_uploaders? || has_translated_carrierwave_uploaders?
|
11
|
+
end
|
12
|
+
|
13
|
+
# class Article
|
14
|
+
# mount_uploader :poster, PosterUploader
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Article.features.has_own_carrierwave_uploaders? => true
|
18
|
+
# Article.features.has_translated_carrierwave_uploaders? => false
|
19
|
+
#
|
20
|
+
def has_own_carrierwave_uploaders?
|
21
|
+
model_class.try(:uploaders).present?
|
22
|
+
end
|
23
|
+
|
24
|
+
# class Article
|
25
|
+
# translates :poster
|
26
|
+
# Translation.mount_uploader :poster, PosterUploader
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Article.features.has_own_carrierwave_uploaders? => false
|
30
|
+
# Article.features.has_translated_carrierwave_uploaders? => true
|
31
|
+
#
|
32
|
+
def has_translated_carrierwave_uploaders?
|
33
|
+
!!with(:globalize) { |g| g.model_class_for_translations.features.has_carrierwave_uploaders? }
|
34
|
+
end
|
35
|
+
|
36
|
+
def carrierwave
|
37
|
+
@carrierwave || begin
|
38
|
+
@carrierwave = CarrierWave.new(env) if has_carrierwave_uploaders?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
serialize do
|
43
|
+
{
|
44
|
+
has_carrierwave_uploaders: has_carrierwave_uploaders?,
|
45
|
+
has_own_carrierwave_uploaders: has_own_carrierwave_uploaders?,
|
46
|
+
has_translated_carrierwave_uploaders: has_translated_carrierwave_uploaders?,
|
47
|
+
carrierwave: carrierwave.try(:to_hash)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
class CarrierWave < Base
|
52
|
+
# class Article
|
53
|
+
# mount_uploader :poster, PosterUploader
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# Article.features.carrierwave.table => { poster: PosterUploader }
|
57
|
+
#
|
58
|
+
def table
|
59
|
+
model_class.uploaders
|
60
|
+
end
|
61
|
+
|
62
|
+
# class Article
|
63
|
+
# mount_uploader :poster, PosterUploader, mount_on: :poster_path
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# Article.features.carrierwave.options => { poster: { mount_on: :poster_path } }
|
67
|
+
#
|
68
|
+
def options
|
69
|
+
model_class.uploader_options
|
70
|
+
end
|
71
|
+
|
72
|
+
# class Article
|
73
|
+
# mount_uploader :poster, PosterUploader, mount_on: :poster_path
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# Article.features.carrierwave.uploader_for(:poster_path) => PosterUploader
|
77
|
+
#
|
78
|
+
def uploader_for(attr_name)
|
79
|
+
attr_name = convert_key(attr_name)
|
80
|
+
|
81
|
+
if pair = pair_for(attr_name)
|
82
|
+
table[pair.first]
|
83
|
+
|
84
|
+
else
|
85
|
+
send_to_translation(:uploader_for, attr_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# class Article
|
90
|
+
# mount_uploader :poster, PosterUploader, mount_on: :poster_path
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# Article.features.carrierwave.accessor_for(:poster_path) => :poster
|
94
|
+
#
|
95
|
+
def accessor_for(attr_name)
|
96
|
+
attr_name = convert_key(attr_name)
|
97
|
+
|
98
|
+
if table.has_key?(attr_name)
|
99
|
+
attr_name
|
100
|
+
|
101
|
+
elsif pair = pair_for(attr_name)
|
102
|
+
pair.first
|
103
|
+
|
104
|
+
else
|
105
|
+
send_to_translation(:accessor_for, attr_name)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
serialize do
|
110
|
+
{
|
111
|
+
table: table,
|
112
|
+
options: options
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
def pair_for(mounted_on_or_attr_name)
|
118
|
+
all_options = options
|
119
|
+
key = convert_key(mounted_on_or_attr_name)
|
120
|
+
|
121
|
+
if all_options.has_key?(key)
|
122
|
+
{key => all_options[key]}
|
123
|
+
else
|
124
|
+
all_options.find do |name, options|
|
125
|
+
options.is_a?(Hash) && (mount_on = options[:mount_on]) && mount_on.to_sym == key
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def convert_key(key)
|
131
|
+
key.is_a?(Symbol) ? key : key.to_sym
|
132
|
+
end
|
133
|
+
|
134
|
+
def send_to_translation(method, *args)
|
135
|
+
model_features.with(:globalize) do |g|
|
136
|
+
g.model_class_for_translations.features.carrierwave.send(method, *args)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: essay-carrierwave
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yaroslav Konoplov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-20 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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: essay
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
description: essay-carrierwave
|
42
|
+
email:
|
43
|
+
- eahome00@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- essay-carrierwave.gemspec
|
53
|
+
- lib/essay-carrierwave.rb
|
54
|
+
- lib/essay-carrierwave/attribute.rb
|
55
|
+
- lib/essay-carrierwave/model.rb
|
56
|
+
homepage: http://github.com/yivo/essay-carrierwave
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.5.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: essay-carrierwave
|
80
|
+
test_files: []
|