carrierwave 0.4.10 → 0.5.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of carrierwave might be problematic. Click here for more details.
- data/README.rdoc +17 -10
- data/lib/carrierwave.rb +11 -6
- data/lib/carrierwave/orm/activerecord.rb +2 -0
- data/lib/carrierwave/processing/image_science.rb +15 -0
- data/lib/carrierwave/processing/mini_magick.rb +2 -6
- data/lib/carrierwave/processing/rmagick.rb +1 -5
- data/lib/carrierwave/test/matchers.rb +2 -2
- data/lib/carrierwave/uploader.rb +13 -13
- data/lib/carrierwave/uploader/cache.rb +4 -3
- data/lib/carrierwave/uploader/callbacks.rb +11 -12
- data/lib/carrierwave/uploader/configuration.rb +3 -1
- data/lib/carrierwave/uploader/download.rb +4 -3
- data/lib/carrierwave/uploader/extension_whitelist.rb +3 -2
- data/lib/carrierwave/uploader/processing.rb +4 -3
- data/lib/carrierwave/uploader/remove.rb +3 -2
- data/lib/carrierwave/uploader/store.rb +5 -4
- data/lib/carrierwave/uploader/versions.rb +4 -3
- data/{rails_generators/uploader → lib/generators}/templates/uploader.rb +0 -0
- data/lib/generators/uploader_generator.rb +13 -0
- metadata +30 -18
- data/Generators +0 -4
- data/lib/carrierwave/core_ext/blank.rb +0 -46
- data/lib/carrierwave/core_ext/inheritable_attributes.rb +0 -104
- data/lib/carrierwave/core_ext/module_setup.rb +0 -51
- data/merb_generators/uploader_generator.rb +0 -22
- data/rails_generators/uploader/USAGE +0 -2
- data/rails_generators/uploader/uploader_generator.rb +0 -21
data/README.rdoc
CHANGED
@@ -14,6 +14,7 @@ upload files.
|
|
14
14
|
* Please {report any issues}[http://github.com/jnicklas/carrierwave/issues] on GitHub
|
15
15
|
* Please direct any questions at the {mailing list}[http://groups.google.com/group/carrierwave]
|
16
16
|
* Check out the {example app}[http://github.com/jnicklas/carrierwave-example-app]
|
17
|
+
* Instructions for setting up a development environment are at the bottom of this file
|
17
18
|
|
18
19
|
== Getting Started
|
19
20
|
|
@@ -275,7 +276,7 @@ It's a good idea to test you uploaders in isolation. In order to speed up your
|
|
275
276
|
tests, it's recommended to switch off processing in your tests, and to use the
|
276
277
|
file storage. In Rails you could do that by adding an initializer with:
|
277
278
|
|
278
|
-
if Rails.env.test?
|
279
|
+
if Rails.env.test? or Rails.env.cucumber?
|
279
280
|
CarrierWave.configure do |config|
|
280
281
|
config.storage = :file
|
281
282
|
config.enable_processing = false
|
@@ -302,7 +303,7 @@ CarrierWave comes with some RSpec matchers which you may find useful:
|
|
302
303
|
|
303
304
|
context 'the thumb version' do
|
304
305
|
it "should scale down a landscape image to be exactly 64 by 64 pixels" do
|
305
|
-
@uploader.thumb.should have_dimensions(
|
306
|
+
@uploader.thumb.should have_dimensions(64, 64)
|
306
307
|
end
|
307
308
|
end
|
308
309
|
|
@@ -313,7 +314,7 @@ CarrierWave comes with some RSpec matchers which you may find useful:
|
|
313
314
|
end
|
314
315
|
|
315
316
|
it "should make the image readable only to the owner and not executable" do
|
316
|
-
@uploader.should
|
317
|
+
@uploader.should have_permissions(0600)
|
317
318
|
end
|
318
319
|
end
|
319
320
|
|
@@ -507,6 +508,9 @@ These people have contributed their time and effort to CarrierWave:
|
|
507
508
|
* Trevor Turk
|
508
509
|
* Nicklas Ramhöj
|
509
510
|
* Matt Hooks
|
511
|
+
* Andreas Haller
|
512
|
+
* Lars Pind
|
513
|
+
* Ramon Soares
|
510
514
|
|
511
515
|
== License
|
512
516
|
|
@@ -533,14 +537,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
533
537
|
|
534
538
|
== Development
|
535
539
|
|
536
|
-
|
537
|
-
|
540
|
+
In order to setup a development environment and run the specs, you'll
|
541
|
+
need to install bundler:
|
538
542
|
|
539
|
-
|
543
|
+
gem install bundler --pre
|
540
544
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
+
And then install the dependencies:
|
546
|
+
|
547
|
+
bundle install
|
548
|
+
|
549
|
+
You should now be able to run the tests:
|
550
|
+
|
551
|
+
bundle exec rake spec
|
545
552
|
|
546
553
|
Issues are reported on GitHub, pull requests are very welcome!
|
data/lib/carrierwave.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'active_support/core_ext/class/inheritable_attributes'
|
6
|
+
require 'active_support/concern'
|
7
7
|
|
8
8
|
module CarrierWave
|
9
9
|
|
10
|
-
VERSION = "0.4.
|
10
|
+
VERSION = "0.4.5"
|
11
11
|
|
12
12
|
class << self
|
13
13
|
attr_accessor :root
|
@@ -80,8 +80,13 @@ if defined?(Merb)
|
|
80
80
|
|
81
81
|
elsif defined?(Rails)
|
82
82
|
|
83
|
-
CarrierWave
|
84
|
-
|
83
|
+
module CarrierWave
|
84
|
+
class Railtie < Rails::Railtie
|
85
|
+
initializer "carrierwave.setup_paths" do
|
86
|
+
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
85
90
|
|
86
91
|
elsif defined?(Sinatra)
|
87
92
|
|
@@ -15,6 +15,8 @@ module CarrierWave
|
|
15
15
|
|
16
16
|
alias_method :read_uploader, :read_attribute
|
17
17
|
alias_method :write_uploader, :write_attribute
|
18
|
+
public :read_uploader
|
19
|
+
public :write_uploader
|
18
20
|
|
19
21
|
validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
|
20
22
|
validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
|
@@ -4,6 +4,21 @@ require "image_science"
|
|
4
4
|
|
5
5
|
module CarrierWave
|
6
6
|
module ImageScience
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def resize_to_limit(width, height)
|
11
|
+
process :resize_to_limit => [width, height]
|
12
|
+
end
|
13
|
+
|
14
|
+
def resize_to_fit(width, height)
|
15
|
+
process :resize_to_fit => [width, height]
|
16
|
+
end
|
17
|
+
|
18
|
+
def resize_to_fill(width, height)
|
19
|
+
process :resize_to_fill => [width, height]
|
20
|
+
end
|
21
|
+
end
|
7
22
|
|
8
23
|
##
|
9
24
|
# Resize the image to fit within the specified dimensions while retaining
|
@@ -56,11 +56,7 @@ module CarrierWave
|
|
56
56
|
#
|
57
57
|
#
|
58
58
|
module MiniMagick
|
59
|
-
|
60
|
-
def self.included(base)
|
61
|
-
super
|
62
|
-
base.extend(ClassMethods)
|
63
|
-
end
|
59
|
+
extend ActiveSupport::Concern
|
64
60
|
|
65
61
|
module ClassMethods
|
66
62
|
def convert(format)
|
@@ -103,7 +99,7 @@ module CarrierWave
|
|
103
99
|
#
|
104
100
|
def convert(format)
|
105
101
|
manipulate! do |img|
|
106
|
-
img.format(format.to_s.
|
102
|
+
img.format(format.to_s.downcase)
|
107
103
|
img = yield(img) if block_given?
|
108
104
|
img
|
109
105
|
end
|
@@ -68,11 +68,7 @@ module CarrierWave
|
|
68
68
|
# http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618
|
69
69
|
#
|
70
70
|
module RMagick
|
71
|
-
|
72
|
-
def self.included(base)
|
73
|
-
super
|
74
|
-
base.extend(ClassMethods)
|
75
|
-
end
|
71
|
+
extend ActiveSupport::Concern
|
76
72
|
|
77
73
|
module ClassMethods
|
78
74
|
def convert(format)
|
@@ -111,10 +111,10 @@ module CarrierWave
|
|
111
111
|
|
112
112
|
class ImageLoader # :nodoc:
|
113
113
|
def self.load_image(filename)
|
114
|
-
if defined? MiniMagick
|
114
|
+
if defined? ::MiniMagick
|
115
115
|
MiniMagickWrapper.new(filename)
|
116
116
|
else
|
117
|
-
unless defined? Magick
|
117
|
+
unless defined? ::Magick
|
118
118
|
begin
|
119
119
|
require 'rmagick'
|
120
120
|
rescue LoadError
|
data/lib/carrierwave/uploader.rb
CHANGED
@@ -25,19 +25,19 @@ module CarrierWave
|
|
25
25
|
class Base
|
26
26
|
attr_reader :file
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
include CarrierWave::Uploader::Callbacks
|
29
|
+
include CarrierWave::Uploader::Proxy
|
30
|
+
include CarrierWave::Uploader::Url
|
31
|
+
include CarrierWave::Uploader::Mountable
|
32
|
+
include CarrierWave::Uploader::Cache
|
33
|
+
include CarrierWave::Uploader::Store
|
34
|
+
include CarrierWave::Uploader::Download
|
35
|
+
include CarrierWave::Uploader::Remove
|
36
|
+
include CarrierWave::Uploader::ExtensionWhitelist
|
37
|
+
include CarrierWave::Uploader::Processing
|
38
|
+
include CarrierWave::Uploader::Versions
|
39
|
+
include CarrierWave::Uploader::DefaultUrl
|
40
|
+
include CarrierWave::Uploader::Configuration
|
41
41
|
end # Base
|
42
42
|
|
43
43
|
end # Uploader
|
@@ -21,9 +21,10 @@ module CarrierWave
|
|
21
21
|
|
22
22
|
module Uploader
|
23
23
|
module Cache
|
24
|
+
extend ActiveSupport::Concern
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
include CarrierWave::Uploader::Callbacks
|
27
|
+
include CarrierWave::Uploader::Configuration
|
27
28
|
|
28
29
|
module ClassMethods
|
29
30
|
|
@@ -38,7 +39,7 @@ module CarrierWave
|
|
38
39
|
# === Note
|
39
40
|
#
|
40
41
|
# This only works as long as you haven't done anything funky with your cache_dir.
|
41
|
-
# It's recommended that you
|
42
|
+
# It's recommended that you keep cache files in one place only.
|
42
43
|
#
|
43
44
|
def clean_cached_files!
|
44
45
|
Dir.glob(File.expand_path(File.join(cache_dir, '*'), CarrierWave.root)).each do |dir|
|
@@ -3,9 +3,10 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module Callbacks
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
included do
|
9
|
+
class_inheritable_accessor :_before_callbacks, :_after_callbacks
|
9
10
|
end
|
10
11
|
|
11
12
|
def with_callbacks(kind, *args)
|
@@ -17,26 +18,24 @@ module CarrierWave
|
|
17
18
|
module ClassMethods
|
18
19
|
|
19
20
|
def _before_callbacks_for(kind) #:nodoc:
|
20
|
-
self._before_callbacks
|
21
|
-
self._before_callbacks[kind] ||= []
|
22
|
-
self._before_callbacks[kind]
|
21
|
+
(self._before_callbacks || { kind => [] })[kind] || []
|
23
22
|
end
|
24
23
|
|
25
24
|
def _after_callbacks_for(kind) #:nodoc:
|
26
|
-
self._after_callbacks
|
27
|
-
self._after_callbacks[kind] ||= []
|
28
|
-
self._after_callbacks[kind]
|
25
|
+
(self._after_callbacks || { kind => [] })[kind] || []
|
29
26
|
end
|
30
27
|
|
31
|
-
def before(kind, callback)
|
32
|
-
|
28
|
+
def before(kind, callback)
|
29
|
+
self._before_callbacks ||= {}
|
30
|
+
self._before_callbacks[kind] = _before_callbacks_for(kind) + [callback]
|
33
31
|
end
|
34
32
|
|
35
33
|
def after(kind, callback)
|
36
|
-
|
34
|
+
self._after_callbacks ||= {}
|
35
|
+
self._after_callbacks[kind] = _after_callbacks_for(kind) + [callback]
|
37
36
|
end
|
38
37
|
end # ClassMethods
|
39
38
|
|
40
39
|
end # Callbacks
|
41
40
|
end # Uploader
|
42
|
-
end # CarrierWave
|
41
|
+
end # CarrierWave
|
@@ -5,10 +5,11 @@ require 'net/http'
|
|
5
5
|
module CarrierWave
|
6
6
|
module Uploader
|
7
7
|
module Download
|
8
|
+
extend ActiveSupport::Concern
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
include CarrierWave::Uploader::Callbacks
|
11
|
+
include CarrierWave::Uploader::Configuration
|
12
|
+
include CarrierWave::Uploader::Cache
|
12
13
|
|
13
14
|
class RemoteFile
|
14
15
|
def initialize(uri)
|
@@ -3,8 +3,9 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module ExtensionWhitelist
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
+
included do
|
8
9
|
before :cache, :check_whitelist!
|
9
10
|
end
|
10
11
|
|
@@ -34,4 +35,4 @@ module CarrierWave
|
|
34
35
|
|
35
36
|
end # ExtensionWhitelist
|
36
37
|
end # Uploader
|
37
|
-
end # CarrierWave
|
38
|
+
end # CarrierWave
|
@@ -3,10 +3,11 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module Processing
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
+
include CarrierWave::Uploader::Callbacks
|
8
9
|
|
9
|
-
|
10
|
+
included do
|
10
11
|
after :cache, :process!
|
11
12
|
after :recreate_versions, :process!
|
12
13
|
end
|
@@ -81,4 +82,4 @@ module CarrierWave
|
|
81
82
|
|
82
83
|
end # Processing
|
83
84
|
end # Uploader
|
84
|
-
end # CarrierWave
|
85
|
+
end # CarrierWave
|
@@ -3,8 +3,9 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module Remove
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
+
include CarrierWave::Uploader::Callbacks
|
8
9
|
|
9
10
|
##
|
10
11
|
# Removes the file and reset it
|
@@ -19,4 +20,4 @@ module CarrierWave
|
|
19
20
|
|
20
21
|
end # Remove
|
21
22
|
end # Uploader
|
22
|
-
end # CarrierWave
|
23
|
+
end # CarrierWave
|
@@ -3,10 +3,11 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module Store
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
include CarrierWave::Uploader::Callbacks
|
9
|
+
include CarrierWave::Uploader::Configuration
|
10
|
+
include CarrierWave::Uploader::Cache
|
10
11
|
|
11
12
|
##
|
12
13
|
# Override this in your Uploader to change the filename.
|
@@ -86,4 +87,4 @@ module CarrierWave
|
|
86
87
|
|
87
88
|
end # Store
|
88
89
|
end # Uploader
|
89
|
-
end # CarrierWave
|
90
|
+
end # CarrierWave
|
@@ -3,10 +3,11 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module Versions
|
6
|
+
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
|
+
include CarrierWave::Uploader::Callbacks
|
8
9
|
|
9
|
-
|
10
|
+
included do
|
10
11
|
after :cache, :cache_versions!
|
11
12
|
after :store, :store_versions!
|
12
13
|
after :remove, :remove_versions!
|
@@ -153,4 +154,4 @@ module CarrierWave
|
|
153
154
|
|
154
155
|
end # Versions
|
155
156
|
end # Uploader
|
156
|
-
end # CarrierWave
|
157
|
+
end # CarrierWave
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
class UploaderGenerator < Rails::Generators::NamedBase
|
5
|
+
def create_uploader_file
|
6
|
+
template 'uploader.rb', File.join('app/uploaders', class_path, "#{file_name}.rb")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: true
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
- beta2
|
10
|
+
version: 0.5.0.beta2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jonas Nicklas
|
@@ -14,10 +15,25 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-21 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
- beta4
|
34
|
+
version: 3.0.0.beta4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
21
37
|
description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
|
22
38
|
email:
|
23
39
|
- jonas.nicklas@gmail.com
|
@@ -29,9 +45,6 @@ extra_rdoc_files:
|
|
29
45
|
- README.rdoc
|
30
46
|
files:
|
31
47
|
- lib/carrierwave/compatibility/paperclip.rb
|
32
|
-
- lib/carrierwave/core_ext/blank.rb
|
33
|
-
- lib/carrierwave/core_ext/inheritable_attributes.rb
|
34
|
-
- lib/carrierwave/core_ext/module_setup.rb
|
35
48
|
- lib/carrierwave/mount.rb
|
36
49
|
- lib/carrierwave/orm/activerecord.rb
|
37
50
|
- lib/carrierwave/orm/datamapper.rb
|
@@ -63,12 +76,9 @@ files:
|
|
63
76
|
- lib/carrierwave/uploader/versions.rb
|
64
77
|
- lib/carrierwave/uploader.rb
|
65
78
|
- lib/carrierwave.rb
|
66
|
-
-
|
67
|
-
-
|
68
|
-
- rails_generators/uploader/USAGE
|
69
|
-
- merb_generators/uploader_generator.rb
|
79
|
+
- lib/generators/templates/uploader.rb
|
80
|
+
- lib/generators/uploader_generator.rb
|
70
81
|
- README.rdoc
|
71
|
-
- Generators
|
72
82
|
has_rdoc: true
|
73
83
|
homepage: http://carrierwave.rubyforge.org
|
74
84
|
licenses: []
|
@@ -90,11 +100,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
101
|
none: false
|
92
102
|
requirements:
|
93
|
-
- - "
|
103
|
+
- - ">"
|
94
104
|
- !ruby/object:Gem::Version
|
95
105
|
segments:
|
96
|
-
-
|
97
|
-
|
106
|
+
- 1
|
107
|
+
- 3
|
108
|
+
- 1
|
109
|
+
version: 1.3.1
|
98
110
|
requirements: []
|
99
111
|
|
100
112
|
rubyforge_project: carrierwave
|
data/Generators
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
unless "".respond_to?(:blank?)
|
4
|
-
# blank? methods for several different class types
|
5
|
-
class Object
|
6
|
-
# Returns true if the object is nil or empty (if applicable)
|
7
|
-
def blank?
|
8
|
-
nil? || (respond_to?(:empty?) && empty?)
|
9
|
-
end
|
10
|
-
end # class Object
|
11
|
-
|
12
|
-
class Numeric
|
13
|
-
# Numerics can't be blank
|
14
|
-
def blank?
|
15
|
-
false
|
16
|
-
end
|
17
|
-
end # class Numeric
|
18
|
-
|
19
|
-
class NilClass
|
20
|
-
# Nils are always blank
|
21
|
-
def blank?
|
22
|
-
true
|
23
|
-
end
|
24
|
-
end # class NilClass
|
25
|
-
|
26
|
-
class TrueClass
|
27
|
-
# True is not blank.
|
28
|
-
def blank?
|
29
|
-
false
|
30
|
-
end
|
31
|
-
end # class TrueClass
|
32
|
-
|
33
|
-
class FalseClass
|
34
|
-
# False is always blank.
|
35
|
-
def blank?
|
36
|
-
true
|
37
|
-
end
|
38
|
-
end # class FalseClass
|
39
|
-
|
40
|
-
class String
|
41
|
-
# Strips out whitespace then tests if the string is empty.
|
42
|
-
def blank?
|
43
|
-
strip.empty?
|
44
|
-
end
|
45
|
-
end # class String
|
46
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Stolen from Rails 3
|
4
|
-
|
5
|
-
# Copyright (c) 2005-2009 David Heinemeier Hansson
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
-
# a copy of this software and associated documentation files (the
|
9
|
-
# "Software"), to deal in the Software without restriction, including
|
10
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
13
|
-
# the following conditions:
|
14
|
-
#
|
15
|
-
# The above copyright notice and this permission notice shall be
|
16
|
-
# included in all copies or substantial portions of the Software.
|
17
|
-
#
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
-
|
26
|
-
# Retain for backward compatibility. Methods are now included in Class.
|
27
|
-
class Class
|
28
|
-
# Defines class-level inheritable attribute reader. Attributes are available to subclasses,
|
29
|
-
# each subclass has a copy of parent's attribute.
|
30
|
-
#
|
31
|
-
# @param *syms<Array[#to_s]> Array of attributes to define inheritable reader for.
|
32
|
-
# @return <Array[#to_s]> Array of attributes converted into inheritable_readers.
|
33
|
-
#
|
34
|
-
# @api public
|
35
|
-
#
|
36
|
-
# @todo Do we want to block instance_reader via :instance_reader => false
|
37
|
-
# @todo It would be preferable that we do something with a Hash passed in
|
38
|
-
# (error out or do the same as other methods above) instead of silently
|
39
|
-
# moving on). In particular, this makes the return value of this function
|
40
|
-
# less useful.
|
41
|
-
def extlib_inheritable_reader(*ivars)
|
42
|
-
instance_reader = ivars.pop[:reader] if ivars.last.is_a?(Hash)
|
43
|
-
|
44
|
-
ivars.each do |ivar|
|
45
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
46
|
-
def self.#{ivar}
|
47
|
-
return @#{ivar} if self.object_id == #{self.object_id} || defined?(@#{ivar})
|
48
|
-
ivar = superclass.#{ivar}
|
49
|
-
return nil if ivar.nil? && !#{self}.instance_variable_defined?("@#{ivar}")
|
50
|
-
@#{ivar} = ivar && !ivar.is_a?(Module) && !ivar.is_a?(Numeric) && !ivar.is_a?(TrueClass) && !ivar.is_a?(FalseClass) ? ivar.dup : ivar
|
51
|
-
end
|
52
|
-
RUBY
|
53
|
-
unless instance_reader == false
|
54
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
55
|
-
def #{ivar}
|
56
|
-
self.class.#{ivar}
|
57
|
-
end
|
58
|
-
RUBY
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end unless Class.respond_to?(:extlib_inheritable_reader)
|
62
|
-
|
63
|
-
# Defines class-level inheritable attribute writer. Attributes are available to subclasses,
|
64
|
-
# each subclass has a copy of parent's attribute.
|
65
|
-
#
|
66
|
-
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
|
67
|
-
# define inheritable writer for.
|
68
|
-
# @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
|
69
|
-
# @return <Array[#to_s]> An Array of the attributes that were made into inheritable writers.
|
70
|
-
#
|
71
|
-
# @api public
|
72
|
-
#
|
73
|
-
# @todo We need a style for class_eval <<-HEREDOC. I'd like to make it
|
74
|
-
# class_eval(<<-RUBY, __FILE__, __LINE__), but we should codify it somewhere.
|
75
|
-
def extlib_inheritable_writer(*ivars)
|
76
|
-
instance_writer = ivars.pop[:writer] if ivars.last.is_a?(Hash)
|
77
|
-
ivars.each do |ivar|
|
78
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
79
|
-
def self.#{ivar}=(obj)
|
80
|
-
@#{ivar} = obj
|
81
|
-
end
|
82
|
-
RUBY
|
83
|
-
unless instance_writer == false
|
84
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
85
|
-
def #{ivar}=(obj) self.class.#{ivar} = obj end
|
86
|
-
RUBY
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end unless Class.respond_to?(:extlib_inheritable_writer)
|
90
|
-
|
91
|
-
# Defines class-level inheritable attribute accessor. Attributes are available to subclasses,
|
92
|
-
# each subclass has a copy of parent's attribute.
|
93
|
-
#
|
94
|
-
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
|
95
|
-
# define inheritable accessor for.
|
96
|
-
# @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
|
97
|
-
# @return <Array[#to_s]> An Array of attributes turned into inheritable accessors.
|
98
|
-
#
|
99
|
-
# @api public
|
100
|
-
def extlib_inheritable_accessor(*syms)
|
101
|
-
extlib_inheritable_reader(*syms)
|
102
|
-
extlib_inheritable_writer(*syms)
|
103
|
-
end unless Class.respond_to?(:extlib_inheritable_accessor)
|
104
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Stolen from Rails 3
|
4
|
-
|
5
|
-
# Copyright (c) 2005-2009 David Heinemeier Hansson
|
6
|
-
#
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
8
|
-
# a copy of this software and associated documentation files (the
|
9
|
-
# "Software"), to deal in the Software without restriction, including
|
10
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
11
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
13
|
-
# the following conditions:
|
14
|
-
#
|
15
|
-
# The above copyright notice and this permission notice shall be
|
16
|
-
# included in all copies or substantial portions of the Software.
|
17
|
-
#
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
-
|
26
|
-
class Module
|
27
|
-
attr_accessor :_setup_block
|
28
|
-
attr_accessor :_dependencies
|
29
|
-
|
30
|
-
def setup(&blk)
|
31
|
-
@_setup_block = blk
|
32
|
-
end
|
33
|
-
|
34
|
-
def use(mod)
|
35
|
-
return if self < mod
|
36
|
-
|
37
|
-
(mod._dependencies || []).each do |dep|
|
38
|
-
use dep
|
39
|
-
end
|
40
|
-
# raise "Circular dependencies" if self < mod
|
41
|
-
include mod
|
42
|
-
extend mod.const_get("ClassMethods") if mod.const_defined?("ClassMethods")
|
43
|
-
class_eval(&mod._setup_block) if mod._setup_block
|
44
|
-
end
|
45
|
-
|
46
|
-
def depends_on(mod)
|
47
|
-
return if self < mod
|
48
|
-
@_dependencies ||= []
|
49
|
-
@_dependencies << mod
|
50
|
-
end
|
51
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Merb
|
4
|
-
module Generators
|
5
|
-
class UploaderGenerator < NamedGenerator
|
6
|
-
|
7
|
-
def self.source_root
|
8
|
-
File.join(File.dirname(__FILE__), '..', '..', 'rails_generators', 'uploader', 'templates')
|
9
|
-
end
|
10
|
-
|
11
|
-
first_argument :name, :required => true, :desc => "The name of this uploader"
|
12
|
-
|
13
|
-
template :uploader do |t|
|
14
|
-
t.source = 'uploader.rb'
|
15
|
-
t.destination = "app/uploaders/#{file_name}_uploader.rb"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
add :uploader, UploaderGenerator
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
class UploaderGenerator < Rails::Generator::NamedBase
|
4
|
-
|
5
|
-
def manifest
|
6
|
-
record do |m|
|
7
|
-
m.directory 'app/uploaders'
|
8
|
-
m.template 'uploader.rb', "app/uploaders/#{name.underscore}_uploader.rb"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def class_name
|
13
|
-
name.camelize
|
14
|
-
end
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def banner
|
19
|
-
"Usage: #{$0} uploader UploaderName"
|
20
|
-
end
|
21
|
-
end
|