model_attachment 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Rakefile +19 -68
- data/lib/model_attachment.rb +13 -4
- data/lib/model_attachment/version.rb +3 -0
- data/test/assets/test.jpg +0 -0
- data/test/{model_attachment_test.rb → model_attachment/model_attachment_test.rb} +13 -5
- metadata +25 -36
- data/Manifest.txt +0 -12
- data/init.rb +0 -1
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
#require 'rspec/core/rake_task'
|
5
|
+
#Rspec::Core::RakeTask.new(:spec)
|
6
|
+
|
1
7
|
require 'rake'
|
2
8
|
require 'rake/testtask'
|
3
9
|
require 'rake/rdoctask'
|
4
10
|
|
5
|
-
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
6
|
-
require 'model_attachment'
|
7
|
-
|
8
11
|
desc 'Default: run unit tests.'
|
9
12
|
task :default => [:clean, :test]
|
10
13
|
|
@@ -15,10 +18,13 @@ Rake::TestTask.new(:test) do |t|
|
|
15
18
|
t.verbose = true
|
16
19
|
end
|
17
20
|
|
18
|
-
desc '
|
19
|
-
task :
|
20
|
-
|
21
|
-
|
21
|
+
desc 'Clean up files.'
|
22
|
+
task :clean do |t|
|
23
|
+
FileUtils.rm_rf "doc"
|
24
|
+
FileUtils.rm_rf "tmp"
|
25
|
+
FileUtils.rm_rf "pkg"
|
26
|
+
FileUtils.rm "test/test.log" rescue nil
|
27
|
+
Dir.glob("model_attachment-*.gem").each{|f| FileUtils.rm f }
|
22
28
|
end
|
23
29
|
|
24
30
|
desc 'Generate documentation for the model_attachment plugin.'
|
@@ -30,67 +36,12 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
30
36
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
37
|
end
|
32
38
|
|
33
|
-
|
34
|
-
task :sync_docs => 'rdoc' do
|
35
|
-
`rsync -ave ssh doc/ steve@rsweb2:/var/sites/stephenwalker/shared/system/docs/model_attachment`
|
36
|
-
end
|
39
|
+
gemspec = eval(File.read("model_attachment.gemspec"))
|
37
40
|
|
38
|
-
|
39
|
-
task :
|
40
|
-
FileUtils.rm_rf "doc"
|
41
|
-
FileUtils.rm_rf "tmp"
|
42
|
-
FileUtils.rm_rf "pkg"
|
43
|
-
FileUtils.rm "test/debug.log" rescue nil
|
44
|
-
FileUtils.rm "test/model_attachment.db" rescue nil
|
45
|
-
Dir.glob("model_attachment-*.gem").each{|f| FileUtils.rm f }
|
46
|
-
end
|
47
|
-
|
48
|
-
include_file_globs = ["README*",
|
49
|
-
"LICENSE",
|
50
|
-
"Rakefile",
|
51
|
-
"init.rb",
|
52
|
-
"Manifest.txt",
|
53
|
-
"{generators,lib,tasks,test}/**/*"]
|
54
|
-
|
55
|
-
exclude_file_globs = ["test/amazon.yml",
|
56
|
-
"test/test.log"]
|
57
|
-
|
58
|
-
spec = Gem::Specification.new do |s|
|
59
|
-
s.name = "model_attachment"
|
60
|
-
s.description = "Simple file attachment for ActiveRecord models"
|
61
|
-
s.version = ModelAttachment::VERSION
|
62
|
-
s.author = "Steve Walker"
|
63
|
-
s.email = "steve@blackboxweb.com"
|
64
|
-
s.homepage = "http://github.com/stw/model_attachment"
|
65
|
-
s.platform = Gem::Platform::RUBY
|
66
|
-
s.summary = "Attach files to ActiveRecord models and run commands on images"
|
67
|
-
s.files = FileList[include_file_globs].to_a - FileList[exclude_file_globs].to_a
|
68
|
-
s.require_path = "lib"
|
69
|
-
s.test_files = FileList["test/**/test_*.rb"].to_a
|
70
|
-
s.rubyforge_project = "model_attachment"
|
71
|
-
s.has_rdoc = true
|
72
|
-
s.extra_rdoc_files = FileList["README*"].to_a
|
73
|
-
s.rdoc_options << '--line-numbers' << '--inline-source'
|
74
|
-
s.requirements << "ImageMagick"
|
75
|
-
s.add_development_dependency 'sqlite3-ruby'
|
76
|
-
s.add_development_dependency 'activerecord'
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "Print a list of the files to be put into the gem"
|
80
|
-
task :manifest => :clean do
|
81
|
-
spec.files.each do |file|
|
82
|
-
puts file
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
desc "Generate a gemspec file for GitHub"
|
87
|
-
task :gemspec => :clean do
|
88
|
-
File.open("#{spec.name}.gemspec", 'w') do |f|
|
89
|
-
f.write spec.to_ruby
|
90
|
-
end
|
91
|
-
end
|
41
|
+
task :gem => "#{gemspec.full_name}.gem"
|
42
|
+
task :build => "#{gemspec.full_name}.gem"
|
92
43
|
|
93
|
-
|
94
|
-
|
95
|
-
|
44
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["model_attachment.gemspec"] do
|
45
|
+
system "gem build model_attachment.gemspec"
|
46
|
+
system "gem install model_attachment-#{ModelAttachment::VERSION}.gem"
|
96
47
|
end
|
data/lib/model_attachment.rb
CHANGED
@@ -11,10 +11,10 @@ require 'rubygems'
|
|
11
11
|
require 'yaml'
|
12
12
|
require 'model_attachment/upfile'
|
13
13
|
require 'model_attachment/amazon'
|
14
|
+
require 'model_attachment/version'
|
14
15
|
|
15
16
|
# The base module that gets included in ActiveRecord::Base.
|
16
17
|
module ModelAttachment
|
17
|
-
VERSION = "0.0.13"
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
@@ -50,6 +50,7 @@ module ModelAttachment
|
|
50
50
|
|
51
51
|
if options[:aws] == :default
|
52
52
|
config_file = File.join(Rails.root, "config", "amazon.yml")
|
53
|
+
$stderr.puts "Config: " + config_file
|
53
54
|
if File.exist?(config_file)
|
54
55
|
options[:aws] = config_file
|
55
56
|
include AmazonInstanceMethods
|
@@ -328,8 +329,16 @@ module ModelAttachment
|
|
328
329
|
|
329
330
|
end
|
330
331
|
|
331
|
-
#
|
332
|
+
# Rails 3
|
332
333
|
if Object.const_defined?("ActiveRecord")
|
333
|
-
|
334
|
-
|
334
|
+
ActiveSupport.on_load(:active_record) do
|
335
|
+
include ModelAttachment
|
336
|
+
File.send(:include, ModelAttachment::Upfile)
|
337
|
+
end
|
335
338
|
end
|
339
|
+
|
340
|
+
# Set it up in our model
|
341
|
+
# if Object.const_defined?("ActiveRecord")
|
342
|
+
# ActiveRecord::Base.send(:include, ModelAttachment)
|
343
|
+
# File.send(:include, ModelAttachment::Upfile)
|
344
|
+
# end
|
data/test/assets/test.jpg
CHANGED
Binary file
|
@@ -9,16 +9,24 @@ require 'test/unit'
|
|
9
9
|
|
10
10
|
require 'rubygems'
|
11
11
|
require 'active_record'
|
12
|
+
require 'logger'
|
12
13
|
require 'fileutils'
|
13
14
|
|
14
|
-
$:.unshift File.dirname(__FILE__) + '
|
15
|
-
require
|
15
|
+
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
16
|
+
require 'model_attachment'
|
16
17
|
|
17
|
-
|
18
|
+
class Rails
|
19
|
+
def self.root
|
20
|
+
File.dirname(__FILE__) + "/.."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RAILS_ROOT = File.dirname(__FILE__) + "/.."
|
18
25
|
|
19
26
|
class Test::Unit::TestCase
|
20
27
|
end
|
21
28
|
|
29
|
+
|
22
30
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
23
31
|
|
24
32
|
# keep AR from printing schema statements
|
@@ -80,7 +88,7 @@ end
|
|
80
88
|
|
81
89
|
class DocumentWithAWS < Document
|
82
90
|
has_attachment :path => "/system/:domain/:folder/:document/:version/",
|
83
|
-
:aws => File.join(
|
91
|
+
:aws => File.join(Rails.root, "amazon.yml"),
|
84
92
|
:types => {
|
85
93
|
:small => { :command => '/opt/local/bin/convert -geometry 100x100' }
|
86
94
|
},
|
@@ -170,7 +178,7 @@ class ModelAttachmentTest < Test::Unit::TestCase
|
|
170
178
|
document.save
|
171
179
|
assert File.exist?(RAILS_ROOT + "/system/bbs/1/1/0/test3.jpg")
|
172
180
|
|
173
|
-
assert_equal "http://localhost:3000/documentwithaws/
|
181
|
+
assert_equal "http://localhost:3000/documentwithaws/1", document.url(:port => "3000")
|
174
182
|
assert_equal "test3.jpg", document.file_name
|
175
183
|
assert_equal String, document.file_name.class
|
176
184
|
assert_equal "image/jpeg", document.content_type
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 14
|
9
|
+
version: 0.0.14
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Steve Walker
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-17 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: aws-s3
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
@@ -28,48 +28,35 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
|
-
type: :
|
31
|
+
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
version: "0"
|
44
|
-
type: :development
|
45
|
-
version_requirements: *id002
|
46
|
-
description: Simple file attachment for ActiveRecord models
|
47
|
-
email: steve@blackboxweb.com
|
33
|
+
description: Simple file attachment gem
|
34
|
+
email:
|
35
|
+
- swalker@walkertek.com
|
48
36
|
executables: []
|
49
37
|
|
50
38
|
extensions: []
|
51
39
|
|
52
|
-
extra_rdoc_files:
|
53
|
-
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
54
42
|
files:
|
55
|
-
- README.rdoc
|
56
|
-
- LICENSE
|
57
|
-
- Rakefile
|
58
|
-
- init.rb
|
59
|
-
- Manifest.txt
|
60
43
|
- lib/model_attachment/amazon.rb
|
61
44
|
- lib/model_attachment/upfile.rb
|
45
|
+
- lib/model_attachment/version.rb
|
62
46
|
- lib/model_attachment.rb
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Gemfile
|
50
|
+
- Rakefile
|
51
|
+
- test/model_attachment/model_attachment_test.rb
|
63
52
|
- test/assets/test.jpg
|
64
|
-
- test/model_attachment_test.rb
|
65
53
|
has_rdoc: true
|
66
54
|
homepage: http://github.com/stw/model_attachment
|
67
55
|
licenses: []
|
68
56
|
|
69
57
|
post_install_message:
|
70
|
-
rdoc_options:
|
71
|
-
|
72
|
-
- --inline-source
|
58
|
+
rdoc_options: []
|
59
|
+
|
73
60
|
require_paths:
|
74
61
|
- lib
|
75
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -86,14 +73,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
73
|
- - ">="
|
87
74
|
- !ruby/object:Gem::Version
|
88
75
|
segments:
|
89
|
-
-
|
90
|
-
|
91
|
-
|
92
|
-
|
76
|
+
- 1
|
77
|
+
- 3
|
78
|
+
- 6
|
79
|
+
version: 1.3.6
|
80
|
+
requirements: []
|
81
|
+
|
93
82
|
rubyforge_project: model_attachment
|
94
83
|
rubygems_version: 1.3.7
|
95
84
|
signing_key:
|
96
85
|
specification_version: 3
|
97
|
-
summary:
|
86
|
+
summary: A simple file attachment gem
|
98
87
|
test_files: []
|
99
88
|
|
data/Manifest.txt
DELETED
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "lib", "model_attachment")
|