dm-paperclip 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Gemfile +29 -0
  2. data/Gemfile.lock +100 -0
  3. data/README.md +145 -0
  4. data/Rakefile +37 -71
  5. data/VERSION +1 -0
  6. data/dm-paperclip.gemspec +103 -0
  7. data/lib/dm-paperclip.rb +88 -74
  8. data/lib/dm-paperclip/attachment.rb +139 -102
  9. data/lib/dm-paperclip/callbacks.rb +55 -0
  10. data/lib/dm-paperclip/command_line.rb +86 -0
  11. data/lib/dm-paperclip/ext/blank.rb +24 -0
  12. data/lib/dm-paperclip/ext/class.rb +50 -0
  13. data/lib/dm-paperclip/ext/compatibility.rb +11 -0
  14. data/lib/dm-paperclip/ext/try_dup.rb +12 -0
  15. data/lib/dm-paperclip/geometry.rb +3 -5
  16. data/lib/dm-paperclip/interpolations.rb +57 -32
  17. data/lib/dm-paperclip/iostream.rb +12 -26
  18. data/lib/dm-paperclip/processor.rb +14 -4
  19. data/lib/dm-paperclip/storage.rb +2 -257
  20. data/lib/dm-paperclip/storage/filesystem.rb +73 -0
  21. data/lib/dm-paperclip/storage/s3.rb +209 -0
  22. data/lib/dm-paperclip/storage/s3/aws_library.rb +41 -0
  23. data/lib/dm-paperclip/storage/s3/aws_s3_library.rb +60 -0
  24. data/lib/dm-paperclip/style.rb +90 -0
  25. data/lib/dm-paperclip/thumbnail.rb +33 -24
  26. data/lib/dm-paperclip/upfile.rb +13 -5
  27. data/lib/dm-paperclip/validations.rb +40 -37
  28. data/lib/dm-paperclip/version.rb +4 -0
  29. data/test/attachment_test.rb +510 -67
  30. data/test/command_line_test.rb +138 -0
  31. data/test/fixtures/s3.yml +8 -0
  32. data/test/fixtures/twopage.pdf +0 -0
  33. data/test/fixtures/uppercase.PNG +0 -0
  34. data/test/geometry_test.rb +54 -19
  35. data/test/helper.rb +91 -28
  36. data/test/integration_test.rb +252 -79
  37. data/test/interpolations_test.rb +150 -0
  38. data/test/iostream_test.rb +8 -15
  39. data/test/paperclip_test.rb +222 -69
  40. data/test/processor_test.rb +10 -0
  41. data/test/storage_test.rb +102 -23
  42. data/test/style_test.rb +141 -0
  43. data/test/thumbnail_test.rb +106 -18
  44. data/test/upfile_test.rb +36 -0
  45. metadata +136 -121
  46. data/README.rdoc +0 -116
  47. data/init.rb +0 -1
  48. data/lib/dm-paperclip/callback_compatability.rb +0 -33
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "dm-core", ">= 1.2.0"
4
+ gem "dm-validations", ">= 1.2.0"
5
+ gem "dm-migrations", ">= 1.2.0"
6
+ gem "extlib", ">= 0"
7
+
8
+ group :development do
9
+ gem "jeweler", "~> 1.8.0"
10
+ gem "yard", "~> 0.8.1"
11
+
12
+ gem "ruby-debug", :platforms => :ruby_18
13
+ gem "debugger", "~> 1.1.3", :platforms => [:ruby_19, :ruby_20]
14
+ end
15
+
16
+ group :test do
17
+ gem "minitest"
18
+ gem "shoulda", ">= 0"
19
+ gem "mocha", "= 0.9.8", :require => false
20
+ gem "aws-s3", ">= 0"
21
+ gem "dm-sqlite-adapter", ">= 0"
22
+ gem "sqlite3"
23
+ gem "data_objects"
24
+ gem "do_sqlite3", "~> 0.10.10"
25
+ gem "database_cleaner", "~> 0.7.2"
26
+
27
+ gem "rcov", "~> 1.0.0", :platforms => :ruby_18
28
+ gem "simplecov", "~> 0.6.4", :platforms => [:ruby_19, :ruby_20]
29
+ end
@@ -0,0 +1,100 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.3)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ addressable (2.2.8)
8
+ aws-s3 (0.6.3)
9
+ builder
10
+ mime-types
11
+ xml-simple
12
+ builder (3.0.0)
13
+ columnize (0.3.6)
14
+ data_objects (0.10.10)
15
+ addressable (~> 2.1)
16
+ database_cleaner (0.7.2)
17
+ debugger (1.1.4)
18
+ columnize (>= 0.3.1)
19
+ debugger-linecache (~> 1.1.1)
20
+ debugger-ruby_core_source (~> 1.1.3)
21
+ debugger-linecache (1.1.2)
22
+ debugger-ruby_core_source (>= 1.1.1)
23
+ debugger-ruby_core_source (1.1.3)
24
+ dm-core (1.2.0)
25
+ addressable (~> 2.2.6)
26
+ dm-do-adapter (1.2.0)
27
+ data_objects (~> 0.10.6)
28
+ dm-core (~> 1.2.0)
29
+ dm-migrations (1.2.0)
30
+ dm-core (~> 1.2.0)
31
+ dm-sqlite-adapter (1.2.0)
32
+ dm-do-adapter (~> 1.2.0)
33
+ do_sqlite3 (~> 0.10.6)
34
+ dm-validations (1.2.0)
35
+ dm-core (~> 1.2.0)
36
+ do_sqlite3 (0.10.10)
37
+ data_objects (= 0.10.10)
38
+ extlib (0.9.15)
39
+ git (1.2.5)
40
+ i18n (0.6.0)
41
+ jeweler (1.8.4)
42
+ bundler (~> 1.0)
43
+ git (>= 1.2.5)
44
+ rake
45
+ rdoc
46
+ json (1.7.3)
47
+ linecache (0.46)
48
+ rbx-require-relative (> 0.0.4)
49
+ mime-types (1.19)
50
+ minitest (4.3.3)
51
+ mocha (0.9.8)
52
+ rake
53
+ multi_json (1.3.6)
54
+ rake (0.9.2.2)
55
+ rbx-require-relative (0.0.9)
56
+ rcov (1.0.0)
57
+ rdoc (3.12)
58
+ json (~> 1.4)
59
+ ruby-debug (0.10.4)
60
+ columnize (>= 0.1)
61
+ ruby-debug-base (~> 0.10.4.0)
62
+ ruby-debug-base (0.10.4)
63
+ linecache (>= 0.3)
64
+ shoulda (3.1.1)
65
+ shoulda-context (~> 1.0)
66
+ shoulda-matchers (~> 1.2)
67
+ shoulda-context (1.0.0)
68
+ shoulda-matchers (1.2.0)
69
+ activesupport (>= 3.0.0)
70
+ simplecov (0.6.4)
71
+ multi_json (~> 1.0)
72
+ simplecov-html (~> 0.5.3)
73
+ simplecov-html (0.5.3)
74
+ sqlite3 (1.3.6)
75
+ xml-simple (1.1.1)
76
+ yard (0.8.2.1)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ aws-s3
83
+ data_objects
84
+ database_cleaner (~> 0.7.2)
85
+ debugger (~> 1.1.3)
86
+ dm-core (>= 1.2.0)
87
+ dm-migrations (>= 1.2.0)
88
+ dm-sqlite-adapter
89
+ dm-validations (>= 1.2.0)
90
+ do_sqlite3 (~> 0.10.10)
91
+ extlib
92
+ jeweler (~> 1.8.0)
93
+ minitest
94
+ mocha (= 0.9.8)
95
+ rcov (~> 1.0.0)
96
+ ruby-debug
97
+ shoulda
98
+ simplecov (~> 0.6.4)
99
+ sqlite3
100
+ yard (~> 0.8.1)
@@ -0,0 +1,145 @@
1
+ # DataMapper Paperclip
2
+
3
+ [![Build Status](https://secure.travis-ci.org/krobertson/dm-paperclip.png?branch=master)](https://travis-ci.org/krobertson/dm-paperclip)
4
+
5
+ DM-Paperclip is a port of Thoughtbot's Paperclip plugin to work with DataMapper.
6
+ This plugin is fully compatible with the original ActiveRecord-oriented
7
+ Paperclip. You could take an existing ActiveRecord database and use it with
8
+ DataMapper. The module also includes updates validation handling and automatic
9
+ including of the necessary 'property' fields into your model.
10
+
11
+ To use it within your models, you need to ensure the three database fields are
12
+ included. They are `{name}_file_name`, `{name}_content_type`, and
13
+ `{name}_file_size`. The first two are strings, the final `_file_size column`
14
+ is an integer. So if your user model has an avatar field, then you would add
15
+ `avatar_file_name`, `avatar_content_type`, and `avatar_file_size`.
16
+
17
+ As with the original Paperclip plugin, it allows processing of thumbnails at
18
+ the time the record is saved though ImageMagick. It processes the thumbnails
19
+ through the command-line applications instead of using RMagick.
20
+
21
+ See the documentation for the `has_attached_file` method for options.
22
+
23
+ ## Code
24
+
25
+ The code DM-Paperclip is available at Github:
26
+
27
+ ```
28
+ git clone git://github.com/krobertson/dm-paperclip.git
29
+ ```
30
+
31
+ It is regularly updated to keep in sync with the latest from Thoughtbot.
32
+
33
+ Releases are tagged within the repository and versioned the same as the
34
+ original model. You can also get the latest release packaged as a gem through
35
+ Rubygems.org:
36
+
37
+ ```
38
+ sudo gem install dm-paperclip
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ In your model:
44
+
45
+ ```ruby
46
+ class User
47
+ include DataMapper::Resource
48
+ include Paperclip::Resource
49
+ property :id, Serial
50
+ property :username, String
51
+ has_attached_file :avatar,
52
+ :styles => { :medium => "300x300>",
53
+ :thumb => "100x100>" }
54
+ end
55
+ ```
56
+
57
+ You will need to add an initializer to configure Paperclip. If on Rails, can
58
+ add a `config/initializers/paperclip.rb`, on Merb can use `config/init.rb` and
59
+ add it to the `Merb::BootLoader.after_app_loads` section. Can also use
60
+ environment configs, rackup file, Rake task, wherever.
61
+
62
+ ```ruby
63
+ Paperclip.configure do |config|
64
+ config.root = Rails.root # the application root to anchor relative urls (defaults to Dir.pwd)
65
+ config.env = Rails.env # server env support, defaults to ENV['RACK_ENV'] or 'development'
66
+ config.use_dm_validations = true # validate attachment sizes and such, defaults to false
67
+ config.processors_path = 'lib/pc' # relative path to look for processors, defaults to 'lib/paperclip_processors'
68
+ end
69
+ ```
70
+
71
+ Your database will need to add four columns, `avatar_file_name` (varchar),
72
+ `avatar_content_type` (varchar), and `avatar_file_size` (integer), and
73
+ `avatar_updated_at` (datetime). You can either add these manually, auto-
74
+ migrate, or use the following migration:
75
+
76
+ ```ruby
77
+ migration( 1, :add_user_paperclip_fields ) do
78
+ up do
79
+ modify_table :users do
80
+ add_column :avatar_file_name, "varchar(255)"
81
+ add_column :avatar_content_type, "varchar(255)"
82
+ add_column :avatar_file_size, "integer"
83
+ add_column :avatar_updated_at, "datetime"
84
+ end
85
+ end
86
+ down do
87
+ modify_table :users do
88
+ drop_columns :avatar_file_name, :avatar_content_type, :avatar_file_size, :avatar_updated_at
89
+ end
90
+ end
91
+ end
92
+ ```
93
+
94
+ In your edit and new views:
95
+
96
+ ```erb
97
+ <% form_for @user, { :action => url(:user), :multipart => true } do %>
98
+ <%= file_field :name => 'avatar' %>
99
+ <% end %>
100
+ ```
101
+
102
+ In your controller:
103
+
104
+ ``` ruby
105
+ def create
106
+ ...
107
+ @user.avatar = params[:avatar]
108
+ end
109
+ ```
110
+
111
+ In your show view:
112
+
113
+ ```erb
114
+ <%= image_tag @user.avatar.url %>
115
+ <%= image_tag @user.avatar.url(:medium) %>
116
+ <%= image_tag @user.avatar.url(:thumb) %>
117
+ ```
118
+
119
+ The following validations are available:
120
+
121
+ ```ruby
122
+ validates_attachment_presence :avatar
123
+ validates_attachment_content_type :avatar, :content_type => "image/png"
124
+ validates_attachment_size :avatar, :in => 1..10240
125
+ validates_attachment_thumbnails :avatar
126
+ ```
127
+
128
+ In order to use validations, you must have loaded the 'dm-validations' gem into
129
+ your app (available as a part of dm-more). If the gem isn't loaded before
130
+ DM-Paperclip is loaded, the validation methods will be excluded. You will also
131
+ need to include `DataMapper::Validate` into your mode:
132
+
133
+ ```ruby
134
+ class User
135
+ include DataMapper::Resource
136
+ include DataMapper::Validate
137
+ include Paperclip::Resource
138
+ property :id, Serial
139
+ property :username, String
140
+ has_attached_file :avatar,
141
+ :styles => { :medium => "300x300>",
142
+ :thumb => "100x100>" }
143
+ validates_attachment_size :avatar, :in => 1..5120
144
+ end
145
+ ```
data/Rakefile CHANGED
@@ -1,15 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
1
5
  require 'rake'
2
6
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
7
 
6
- $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
7
- require 'dm-core'
8
- require 'dm-validations'
9
- require 'dm-paperclip'
8
+ begin
9
+ Bundler.setup(:default, :development)
10
+ rescue Bundler::BundlerError => e
11
+ $stderr.puts e.message
12
+ $stderr.puts "Run `bundle install` to install missing gems"
13
+ end
10
14
 
11
- desc 'Default: run unit tests.'
12
- task :default => [:clean, :test]
15
+ begin
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+
20
+ gem.name = "dm-paperclip"
21
+ gem.author = "Ken Robertson"
22
+ gem.email = "ken@invalidlogic.com"
23
+ gem.homepage = "http://invalidlogic.com/dm-paperclip/"
24
+ gem.platform = Gem::Platform::RUBY
25
+ gem.summary = "File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot"
26
+
27
+ gem.requirements << "ImageMagick"
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+ rescue LoadError
31
+ end
32
+
33
+ begin
34
+ require 'yard'
35
+ YARD::Rake::YardocTask.new
36
+ rescue LoadError
37
+ end
13
38
 
14
39
  # Test tasks
15
40
  desc 'Test the DM-Paperclip library.'
@@ -19,22 +44,15 @@ Rake::TestTask.new(:test) do |t|
19
44
  t.verbose = true
20
45
  end
21
46
 
22
- # Console
47
+ desc 'Default: run unit tests.'
48
+ task :default => [:clean, :test]
49
+
50
+ # Console
23
51
  desc "Open an irb session preloaded with this library"
24
52
  task :console do
25
53
  sh "irb -rubygems -r dm-validations -r dm-migrations -r ./lib/dm-paperclip.rb"
26
54
  end
27
55
 
28
- # Rdoc
29
- desc 'Generate documentation for the paperclip plugin.'
30
- Rake::RDocTask.new(:doc) do |rdoc|
31
- rdoc.rdoc_dir = 'doc'
32
- rdoc.title = 'DM-Paperclip'
33
- rdoc.options << '--line-numbers' << '--inline-source'
34
- rdoc.rdoc_files.include('README.rdoc')
35
- rdoc.rdoc_files.include('lib/**/*.rb')
36
- end
37
-
38
56
  # Code coverage
39
57
  task :coverage do
40
58
  system("rm -fr coverage")
@@ -51,55 +69,3 @@ task :clean do |t|
51
69
  FileUtils.rm_rf "pkg"
52
70
  FileUtils.rm_rf "log"
53
71
  end
54
-
55
- spec = Gem::Specification.new do |s|
56
- s.name = "dm-paperclip"
57
- s.version = Paperclip::VERSION
58
- s.author = "Ken Robertson"
59
- s.email = "ken@invalidlogic.com"
60
- s.homepage = "http://invalidlogic.com/dm-paperclip/"
61
- s.platform = Gem::Platform::RUBY
62
- s.summary = "File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot"
63
- s.files = FileList["README.rdoc",
64
- "LICENSE",
65
- "Rakefile",
66
- "init.rb",
67
- "{lib,tasks,test}/**/*"].to_a
68
- s.require_path = "lib"
69
- s.test_files = FileList["test/**/test_*.rb"].to_a
70
- s.rubyforge_project = "dm-paperclip"
71
- s.has_rdoc = true
72
- s.extra_rdoc_files = ["README.rdoc"]
73
- s.rdoc_options << '--line-numbers' << '--inline-source'
74
- s.requirements << "ImageMagick"
75
- s.requirements << "data_mapper"
76
- end
77
-
78
- Rake::GemPackageTask.new(spec) do |pkg|
79
- pkg.need_tar = true
80
- end
81
-
82
- desc 'Generate gemspec'
83
- task :gemspec do
84
- File.open("#{spec.name}.gemspec", 'w') { |f| f.puts(spec.to_ruby) }
85
- end
86
-
87
- WIN32 = (PLATFORM =~ /win32|cygwin/) rescue nil
88
- SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
89
-
90
- desc "Install #{spec.name} #{spec.version}"
91
- task :install => [ :package ] do
92
- sh "#{SUDO} gem install pkg/#{spec.name}-#{spec.version} --no-update-sources", :verbose => false
93
- end
94
-
95
- desc "Release new version"
96
- task :release => [:test, :gem] do
97
- require 'rubygems'
98
- require 'rubyforge'
99
- r = RubyForge.new
100
- r.login
101
- r.add_release spec.rubyforge_project,
102
- spec.name,
103
- spec.version,
104
- File.join("pkg", "#{spec.name}-#{spec.version}.gem")
105
- end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.5.0
@@ -0,0 +1,103 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "dm-paperclip"
8
+ s.version = "2.5.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ken Robertson"]
12
+ s.date = "2013-07-06"
13
+ s.email = "ken@invalidlogic.com"
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "dm-paperclip.gemspec",
26
+ "lib/dm-paperclip.rb",
27
+ "lib/dm-paperclip/attachment.rb",
28
+ "lib/dm-paperclip/callbacks.rb",
29
+ "lib/dm-paperclip/command_line.rb",
30
+ "lib/dm-paperclip/ext/blank.rb",
31
+ "lib/dm-paperclip/ext/class.rb",
32
+ "lib/dm-paperclip/ext/compatibility.rb",
33
+ "lib/dm-paperclip/ext/try_dup.rb",
34
+ "lib/dm-paperclip/geometry.rb",
35
+ "lib/dm-paperclip/interpolations.rb",
36
+ "lib/dm-paperclip/iostream.rb",
37
+ "lib/dm-paperclip/processor.rb",
38
+ "lib/dm-paperclip/storage.rb",
39
+ "lib/dm-paperclip/storage/filesystem.rb",
40
+ "lib/dm-paperclip/storage/s3.rb",
41
+ "lib/dm-paperclip/storage/s3/aws_library.rb",
42
+ "lib/dm-paperclip/storage/s3/aws_s3_library.rb",
43
+ "lib/dm-paperclip/style.rb",
44
+ "lib/dm-paperclip/thumbnail.rb",
45
+ "lib/dm-paperclip/upfile.rb",
46
+ "lib/dm-paperclip/validations.rb",
47
+ "lib/dm-paperclip/version.rb",
48
+ "tasks/paperclip_tasks.rake",
49
+ "test/attachment_test.rb",
50
+ "test/command_line_test.rb",
51
+ "test/fixtures/12k.png",
52
+ "test/fixtures/50x50.png",
53
+ "test/fixtures/5k.png",
54
+ "test/fixtures/bad.png",
55
+ "test/fixtures/s3.yml",
56
+ "test/fixtures/text.txt",
57
+ "test/fixtures/twopage.pdf",
58
+ "test/fixtures/uppercase.PNG",
59
+ "test/geometry_test.rb",
60
+ "test/helper.rb",
61
+ "test/integration_test.rb",
62
+ "test/interpolations_test.rb",
63
+ "test/iostream_test.rb",
64
+ "test/paperclip_test.rb",
65
+ "test/processor_test.rb",
66
+ "test/storage_test.rb",
67
+ "test/style_test.rb",
68
+ "test/thumbnail_test.rb",
69
+ "test/upfile_test.rb"
70
+ ]
71
+ s.homepage = "http://invalidlogic.com/dm-paperclip/"
72
+ s.require_paths = ["lib"]
73
+ s.requirements = ["ImageMagick"]
74
+ s.rubygems_version = "1.8.24"
75
+ s.summary = "File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot"
76
+
77
+ if s.respond_to? :specification_version then
78
+ s.specification_version = 3
79
+
80
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
+ s.add_runtime_dependency(%q<dm-core>, [">= 1.2.0"])
82
+ s.add_runtime_dependency(%q<dm-validations>, [">= 1.2.0"])
83
+ s.add_runtime_dependency(%q<dm-migrations>, [">= 1.2.0"])
84
+ s.add_runtime_dependency(%q<extlib>, [">= 0"])
85
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
86
+ s.add_development_dependency(%q<yard>, ["~> 0.8.1"])
87
+ else
88
+ s.add_dependency(%q<dm-core>, [">= 1.2.0"])
89
+ s.add_dependency(%q<dm-validations>, [">= 1.2.0"])
90
+ s.add_dependency(%q<dm-migrations>, [">= 1.2.0"])
91
+ s.add_dependency(%q<extlib>, [">= 0"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
93
+ s.add_dependency(%q<yard>, ["~> 0.8.1"])
94
+ end
95
+ else
96
+ s.add_dependency(%q<dm-core>, [">= 1.2.0"])
97
+ s.add_dependency(%q<dm-validations>, [">= 1.2.0"])
98
+ s.add_dependency(%q<dm-migrations>, [">= 1.2.0"])
99
+ s.add_dependency(%q<extlib>, [">= 0"])
100
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
101
+ s.add_dependency(%q<yard>, ["~> 0.8.1"])
102
+ end
103
+ end