paperclip-v2_7-patched-ruby-1_8_6 2.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +14 -0
- data/Appraisals +20 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/NEWS +69 -0
- data/README.md +444 -0
- data/Rakefile +41 -0
- data/cucumber/paperclip_steps.rb +6 -0
- data/features/basic_integration.feature +48 -0
- data/features/rake_tasks.feature +68 -0
- data/features/step_definitions/attachment_steps.rb +65 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +193 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +209 -0
- data/features/support/env.rb +8 -0
- data/features/support/fakeweb.rb +3 -0
- data/features/support/fixtures/.boot_config.rb.swo +0 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +46 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/rails2.gemfile +9 -0
- data/gemfiles/rails3.gemfile +9 -0
- data/gemfiles/rails3_1.gemfile +9 -0
- data/gemfiles/rails3_2.gemfile +9 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +4 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +33 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip.rb +493 -0
- data/lib/paperclip/attachment.rb +491 -0
- data/lib/paperclip/attachment_options.rb +10 -0
- data/lib/paperclip/callback_compatibility.rb +61 -0
- data/lib/paperclip/geometry.rb +120 -0
- data/lib/paperclip/interpolations.rb +174 -0
- data/lib/paperclip/iostream.rb +45 -0
- data/lib/paperclip/matchers.rb +64 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
- data/lib/paperclip/missing_attachment_styles.rb +87 -0
- data/lib/paperclip/processor.rb +58 -0
- data/lib/paperclip/railtie.rb +35 -0
- data/lib/paperclip/schema.rb +39 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/storage/filesystem.rb +81 -0
- data/lib/paperclip/storage/fog.rb +191 -0
- data/lib/paperclip/storage/s3.rb +351 -0
- data/lib/paperclip/style.rb +103 -0
- data/lib/paperclip/thumbnail.rb +105 -0
- data/lib/paperclip/upfile.rb +64 -0
- data/lib/paperclip/url_generator.rb +64 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/tasks/paperclip.rake +101 -0
- data/paperclip.gemspec +41 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +124 -0
- data/test/attachment_options_test.rb +40 -0
- data/test/attachment_test.rb +1211 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/animated.gif +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/fog.yml +8 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/spaced file.png +0 -0
- data/test/fixtures/text.txt +1 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +206 -0
- data/test/helper.rb +181 -0
- data/test/integration_test.rb +652 -0
- data/test/interpolations_test.rb +219 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +24 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +110 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +47 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +72 -0
- data/test/paperclip_missing_attachment_styles_test.rb +96 -0
- data/test/paperclip_test.rb +409 -0
- data/test/processor_test.rb +10 -0
- data/test/schema_test.rb +98 -0
- data/test/storage/filesystem_test.rb +62 -0
- data/test/storage/fog_test.rb +280 -0
- data/test/storage/s3_live_test.rb +138 -0
- data/test/storage/s3_test.rb +1093 -0
- data/test/style_test.rb +215 -0
- data/test/support/mock_attachment.rb +22 -0
- data/test/support/mock_interpolator.rb +24 -0
- data/test/support/mock_model.rb +2 -0
- data/test/support/mock_url_generator_builder.rb +27 -0
- data/test/thumbnail_test.rb +396 -0
- data/test/upfile_test.rb +53 -0
- data/test/url_generator_test.rb +187 -0
- metadata +374 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Shoulda
|
3
|
+
module Matchers
|
4
|
+
# Ensures that the given instance or class has an attachment with the
|
5
|
+
# given name.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# describe User do
|
9
|
+
# it { should have_attached_file(:avatar) }
|
10
|
+
# end
|
11
|
+
def have_attached_file name
|
12
|
+
HaveAttachedFileMatcher.new(name)
|
13
|
+
end
|
14
|
+
|
15
|
+
class HaveAttachedFileMatcher
|
16
|
+
def initialize attachment_name
|
17
|
+
@attachment_name = attachment_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches? subject
|
21
|
+
@subject = subject
|
22
|
+
@subject = @subject.class unless Class === @subject
|
23
|
+
responds? && has_column? && included?
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_message
|
27
|
+
"Should have an attachment named #{@attachment_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def negative_failure_message
|
31
|
+
"Should not have an attachment named #{@attachment_name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def description
|
35
|
+
"have an attachment named #{@attachment_name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def responds?
|
41
|
+
methods = @subject.instance_methods.map(&:to_s)
|
42
|
+
methods.include?("#{@attachment_name}") &&
|
43
|
+
methods.include?("#{@attachment_name}=") &&
|
44
|
+
methods.include?("#{@attachment_name}?")
|
45
|
+
end
|
46
|
+
|
47
|
+
def has_column?
|
48
|
+
@subject.column_names.include?("#{@attachment_name}_file_name")
|
49
|
+
end
|
50
|
+
|
51
|
+
def included?
|
52
|
+
@subject.ancestors.include?(Paperclip::InstanceMethods)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Shoulda
|
3
|
+
module Matchers
|
4
|
+
# Ensures that the given instance or class validates the content type of
|
5
|
+
# the given attachment as specified.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# describe User do
|
9
|
+
# it { should validate_attachment_content_type(:icon).
|
10
|
+
# allowing('image/png', 'image/gif').
|
11
|
+
# rejecting('text/plain', 'text/xml') }
|
12
|
+
# end
|
13
|
+
def validate_attachment_content_type name
|
14
|
+
ValidateAttachmentContentTypeMatcher.new(name)
|
15
|
+
end
|
16
|
+
|
17
|
+
class ValidateAttachmentContentTypeMatcher
|
18
|
+
def initialize attachment_name
|
19
|
+
@attachment_name = attachment_name
|
20
|
+
@allowed_types = []
|
21
|
+
@rejected_types = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def allowing *types
|
25
|
+
@allowed_types = types.flatten
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def rejecting *types
|
30
|
+
@rejected_types = types.flatten
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def matches? subject
|
35
|
+
@subject = subject
|
36
|
+
@subject = @subject.new if @subject.class == Class
|
37
|
+
@allowed_types && @rejected_types &&
|
38
|
+
allowed_types_allowed? && rejected_types_rejected?
|
39
|
+
end
|
40
|
+
|
41
|
+
def failure_message
|
42
|
+
"".tap do |str|
|
43
|
+
str << "Content types #{@allowed_types.join(", ")} should be accepted" if @allowed_types.present?
|
44
|
+
str << "\n" if @allowed_types.present? && @rejected_types.present?
|
45
|
+
str << "Content types #{@rejected_types.join(", ")} should be rejected by #{@attachment_name}" if @rejected_types.present?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def negative_failure_message
|
50
|
+
"".tap do |str|
|
51
|
+
str << "Content types #{@allowed_types.join(", ")} should be rejected" if @allowed_types.present?
|
52
|
+
str << "\n" if @allowed_types.present? && @rejected_types.present?
|
53
|
+
str << "Content types #{@rejected_types.join(", ")} should be accepted by #{@attachment_name}" if @rejected_types.present?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def description
|
58
|
+
"validate the content types allowed on attachment #{@attachment_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def type_allowed?(type)
|
64
|
+
file = StringIO.new(".")
|
65
|
+
file.content_type = type
|
66
|
+
@subject.attachment_for(@attachment_name).assign(file)
|
67
|
+
@subject.valid?
|
68
|
+
@subject.errors[:"#{@attachment_name}_content_type"].blank?
|
69
|
+
end
|
70
|
+
|
71
|
+
def allowed_types_allowed?
|
72
|
+
@allowed_types.all? { |type| type_allowed?(type) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def rejected_types_rejected?
|
76
|
+
!@rejected_types.any? { |type| type_allowed?(type) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Shoulda
|
3
|
+
module Matchers
|
4
|
+
# Ensures that the given instance or class validates the presence of the
|
5
|
+
# given attachment.
|
6
|
+
#
|
7
|
+
# describe User do
|
8
|
+
# it { should validate_attachment_presence(:avatar) }
|
9
|
+
# end
|
10
|
+
def validate_attachment_presence name
|
11
|
+
ValidateAttachmentPresenceMatcher.new(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
class ValidateAttachmentPresenceMatcher
|
15
|
+
def initialize attachment_name
|
16
|
+
@attachment_name = attachment_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches? subject
|
20
|
+
@subject = subject
|
21
|
+
@subject = subject.new if subject.class == Class
|
22
|
+
error_when_not_valid? && no_error_when_valid?
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message
|
26
|
+
"Attachment #{@attachment_name} should be required"
|
27
|
+
end
|
28
|
+
|
29
|
+
def negative_failure_message
|
30
|
+
"Attachment #{@attachment_name} should not be required"
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
"require presence of attachment #{@attachment_name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def error_when_not_valid?
|
40
|
+
@subject.send(@attachment_name).assign(nil)
|
41
|
+
@subject.valid?
|
42
|
+
not @subject.errors[:"#{@attachment_name}_file_name"].blank?
|
43
|
+
end
|
44
|
+
|
45
|
+
def no_error_when_valid?
|
46
|
+
@file = StringIO.new(".")
|
47
|
+
@subject.send(@attachment_name).assign(@file)
|
48
|
+
@subject.valid?
|
49
|
+
@subject.errors[:"#{@attachment_name}_file_name"].blank?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Shoulda
|
3
|
+
module Matchers
|
4
|
+
# Ensures that the given instance or class validates the size of the
|
5
|
+
# given attachment as specified.
|
6
|
+
#
|
7
|
+
# Examples:
|
8
|
+
# it { should validate_attachment_size(:avatar).
|
9
|
+
# less_than(2.megabytes) }
|
10
|
+
# it { should validate_attachment_size(:icon).
|
11
|
+
# greater_than(1024) }
|
12
|
+
# it { should validate_attachment_size(:icon).
|
13
|
+
# in(0..100) }
|
14
|
+
def validate_attachment_size name
|
15
|
+
ValidateAttachmentSizeMatcher.new(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
class ValidateAttachmentSizeMatcher
|
19
|
+
def initialize attachment_name
|
20
|
+
@attachment_name = attachment_name
|
21
|
+
@low, @high = 0, (1.0/0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def less_than size
|
25
|
+
@high = size
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def greater_than size
|
30
|
+
@low = size
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def in range
|
35
|
+
@low, @high = range.first, range.last
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def matches? subject
|
40
|
+
@subject = subject
|
41
|
+
@subject = @subject.new if @subject.class == Class
|
42
|
+
lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high?
|
43
|
+
end
|
44
|
+
|
45
|
+
def failure_message
|
46
|
+
"Attachment #{@attachment_name} must be between #{@low} and #{@high} bytes"
|
47
|
+
end
|
48
|
+
|
49
|
+
def negative_failure_message
|
50
|
+
"Attachment #{@attachment_name} cannot be between #{@low} and #{@high} bytes"
|
51
|
+
end
|
52
|
+
|
53
|
+
def description
|
54
|
+
"validate the size of attachment #{@attachment_name}"
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def override_method object, method, &replacement
|
60
|
+
(class << object; self; end).class_eval do
|
61
|
+
define_method(method, &replacement)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def passes_validation_with_size(new_size)
|
66
|
+
file = StringIO.new(".")
|
67
|
+
override_method(file, :size){ new_size }
|
68
|
+
override_method(file, :to_tempfile){ file }
|
69
|
+
|
70
|
+
@subject.send(@attachment_name).assign(file)
|
71
|
+
@subject.valid?
|
72
|
+
@subject.errors[:"#{@attachment_name}_file_size"].blank?
|
73
|
+
end
|
74
|
+
|
75
|
+
def lower_than_low?
|
76
|
+
not passes_validation_with_size(@low - 1)
|
77
|
+
end
|
78
|
+
|
79
|
+
def higher_than_low?
|
80
|
+
passes_validation_with_size(@low + 1)
|
81
|
+
end
|
82
|
+
|
83
|
+
def lower_than_high?
|
84
|
+
return true if @high == (1.0/0)
|
85
|
+
passes_validation_with_size(@high - 1)
|
86
|
+
end
|
87
|
+
|
88
|
+
def higher_than_high?
|
89
|
+
return true if @high == (1.0/0)
|
90
|
+
not passes_validation_with_size(@high + 1)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
require 'set'
|
3
|
+
module Paperclip
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :classes_with_attachments
|
7
|
+
attr_writer :registered_attachments_styles_path
|
8
|
+
def registered_attachments_styles_path
|
9
|
+
@registered_attachments_styles_path ||= Rails.root.join('public/system/paperclip_attachments.yml').to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
self.classes_with_attachments = Set.new
|
14
|
+
|
15
|
+
|
16
|
+
# Get list of styles saved on previous deploy (running rake paperclip:refresh:missing_styles)
|
17
|
+
def self.get_registered_attachments_styles
|
18
|
+
YAML.load_file(Paperclip.registered_attachments_styles_path)
|
19
|
+
rescue Errno::ENOENT
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
private_class_method :get_registered_attachments_styles
|
23
|
+
|
24
|
+
def self.save_current_attachments_styles!
|
25
|
+
File.open(Paperclip.registered_attachments_styles_path, 'w') do |f|
|
26
|
+
YAML.dump(current_attachments_styles, f)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns hash with styles for all classes using Paperclip.
|
31
|
+
# Unfortunately current version does not work with lambda styles:(
|
32
|
+
# {
|
33
|
+
# :User => {:avatar => [:small, :big]},
|
34
|
+
# :Book => {
|
35
|
+
# :cover => [:thumb, :croppable]},
|
36
|
+
# :sample => [:thumb, :big]},
|
37
|
+
# }
|
38
|
+
# }
|
39
|
+
def self.current_attachments_styles
|
40
|
+
Hash.new.tap do |current_styles|
|
41
|
+
Paperclip.classes_with_attachments.each do |klass_name|
|
42
|
+
klass = Paperclip.class_for(klass_name)
|
43
|
+
klass.attachment_definitions.each do |attachment_name, attachment_attributes|
|
44
|
+
# TODO: is it even possible to take into account Procs?
|
45
|
+
next if attachment_attributes[:styles].kind_of?(Proc)
|
46
|
+
attachment_attributes[:styles].try(:keys).try(:each) do |style_name|
|
47
|
+
klass_sym = klass.to_s.to_sym
|
48
|
+
current_styles[klass_sym] ||= Hash.new
|
49
|
+
current_styles[klass_sym][attachment_name.to_sym] ||= Array.new
|
50
|
+
current_styles[klass_sym][attachment_name.to_sym] << style_name.to_sym
|
51
|
+
current_styles[klass_sym][attachment_name.to_sym].map!(&:to_s).sort!.map!(&:to_sym).uniq!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
private_class_method :current_attachments_styles
|
58
|
+
|
59
|
+
# Returns hash with styles missing from recent run of rake paperclip:refresh:missing_styles
|
60
|
+
# {
|
61
|
+
# :User => {:avatar => [:big]},
|
62
|
+
# :Book => {
|
63
|
+
# :cover => [:croppable]},
|
64
|
+
# }
|
65
|
+
# }
|
66
|
+
def self.missing_attachments_styles
|
67
|
+
current_styles = current_attachments_styles
|
68
|
+
registered_styles = get_registered_attachments_styles
|
69
|
+
|
70
|
+
Hash.new.tap do |missing_styles|
|
71
|
+
current_styles.each do |klass, attachment_definitions|
|
72
|
+
attachment_definitions.each do |attachment_name, styles|
|
73
|
+
registered = registered_styles[klass][attachment_name] || [] rescue []
|
74
|
+
missed = styles - registered
|
75
|
+
if missed.present?
|
76
|
+
klass_sym = klass.to_s.to_sym
|
77
|
+
missing_styles[klass_sym] ||= Hash.new
|
78
|
+
missing_styles[klass_sym][attachment_name.to_sym] ||= Array.new
|
79
|
+
missing_styles[klass_sym][attachment_name.to_sym].concat(missed.to_a)
|
80
|
+
missing_styles[klass_sym][attachment_name.to_sym].map!(&:to_s).sort!.map!(&:to_sym).uniq!
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Paperclip
|
2
|
+
# Paperclip processors allow you to modify attached files when they are
|
3
|
+
# attached in any way you are able. Paperclip itself uses command-line
|
4
|
+
# programs for its included Thumbnail processor, but custom processors
|
5
|
+
# are not required to follow suit.
|
6
|
+
#
|
7
|
+
# Processors are required to be defined inside the Paperclip module and
|
8
|
+
# are also required to be a subclass of Paperclip::Processor. There is
|
9
|
+
# only one method you *must* implement to properly be a subclass:
|
10
|
+
# #make, but #initialize may also be of use. Both methods accept 3
|
11
|
+
# arguments: the file that will be operated on (which is an instance of
|
12
|
+
# File), a hash of options that were defined in has_attached_file's
|
13
|
+
# style hash, and the Paperclip::Attachment itself.
|
14
|
+
#
|
15
|
+
# All #make needs to return is an instance of File (Tempfile is
|
16
|
+
# acceptable) which contains the results of the processing.
|
17
|
+
#
|
18
|
+
# See Paperclip.run for more information about using command-line
|
19
|
+
# utilities from within Processors.
|
20
|
+
class Processor
|
21
|
+
attr_accessor :file, :options, :attachment
|
22
|
+
|
23
|
+
def initialize file, options = {}, attachment = nil
|
24
|
+
@file = file
|
25
|
+
@options = options
|
26
|
+
@attachment = attachment
|
27
|
+
end
|
28
|
+
|
29
|
+
def make
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.make file, options = {}, attachment = nil
|
33
|
+
new(file, options, attachment).make
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Due to how ImageMagick handles its image format conversion and how Tempfile
|
38
|
+
# handles its naming scheme, it is necessary to override how Tempfile makes
|
39
|
+
# its names so as to allow for file extensions. Idea taken from the comments
|
40
|
+
# on this blog post:
|
41
|
+
# http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
|
42
|
+
class Tempfile < ::Tempfile
|
43
|
+
# This is Ruby 1.8.7's implementation.
|
44
|
+
if RUBY_VERSION <= "1.8.6" || RUBY_PLATFORM =~ /java/
|
45
|
+
def make_tmpname(basename, n)
|
46
|
+
case basename
|
47
|
+
when Array
|
48
|
+
prefix, suffix = *basename
|
49
|
+
else
|
50
|
+
prefix, suffix = basename, ''
|
51
|
+
end
|
52
|
+
|
53
|
+
t = Time.now.strftime("%y%m%d")
|
54
|
+
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
require 'paperclip/schema'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
if defined? Rails::Railtie
|
6
|
+
require 'rails'
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
initializer 'paperclip.insert_into_active_record' do
|
9
|
+
ActiveSupport.on_load :active_record do
|
10
|
+
Paperclip::Railtie.insert
|
11
|
+
end
|
12
|
+
end
|
13
|
+
rake_tasks do
|
14
|
+
load "tasks/paperclip.rake"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Railtie
|
20
|
+
def self.insert
|
21
|
+
Paperclip.options[:logger] = Rails.logger if defined?(Rails)
|
22
|
+
|
23
|
+
if defined?(ActiveRecord)
|
24
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
25
|
+
Paperclip.options[:logger] = ActiveRecord::Base.logger
|
26
|
+
|
27
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Paperclip::Schema)
|
28
|
+
ActiveRecord::ConnectionAdapters::Table.send(:include, Paperclip::Schema)
|
29
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Paperclip::Schema)
|
30
|
+
end
|
31
|
+
|
32
|
+
File.send(:include, Paperclip::Upfile)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|