glebtv-mongoid-paperclip 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +17 -4
- data/.travis.yml +19 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +42 -11
- data/README.md +5 -1
- data/gemfiles/mongoid-3.1.gemfile +5 -0
- data/gemfiles/mongoid-4.0.gemfile +5 -0
- data/glebtv-mongoid-paperclip.gemspec +3 -1
- data/lib/glebtv-mongoid-paperclip.rb +1 -105
- data/lib/mongoid-paperclip/version.rb +1 -1
- data/lib/mongoid-paperclip.rb +125 -0
- data/spec/mongoid_paperclip_spec.rb +64 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/1024x768.gif +0 -0
- metadata +54 -13
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MDQ3NjQzMjU3NmM3YzBjNzdjMjM1Mjg3OTg4YzhhNjgzNDkyODlhNjZkZmVi
|
10
|
-
YzFiMTk2MTdjNjM1YmU2MTZhMWJiZDQ2NjBkY2FmMzI0NTI5OTU2ODhjYTY1
|
11
|
-
NWRiOGE3ZWJmN2Y3MWMwZTU2ZTAwODU2NGQ5ZDlmYTQ2MDdhYmY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZGMwMmE0ZTA0NDMwNjMyY2EyNDZkZGMyMmU2NWE5MDI0YzJmMThiNDNkNzk1
|
14
|
-
Y2RlOGVkNzlmYTdmMjUwODlkMmMxODc0ZjNkM2M3MDU4YjY2OTYzOGY5MzUx
|
15
|
-
NDI3OWVmYzc1NmRmOTdmNjkwYTNiYzA4ODU3MmNjNjVjNzFkN2I=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ceed3a9c17c2536f40a9a0ae4c49bf625e4a38c
|
4
|
+
data.tar.gz: b313778d936567e35b839781f2c4e19aa774b9be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8de6e40f0576aea85b5e07d6b0aee30d351ab18408c3094491fd8dfe6d969285c4d7dfac55bee32e426017719616eaee9966fe8221ec4670b1b8da00555ad366
|
7
|
+
data.tar.gz: cbef77213caf0bf2dc9d663b5e4ccc8a19f3c10a6286ed9ce21fc603c0ef8ef485e018c33aff38f12d7e4774b1bb1cbdb36c88da13114f1124ee5db3a41dc45d
|
data/.gitignore
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
services: mongodb
|
2
|
+
|
3
|
+
notifications:
|
4
|
+
email: false
|
5
|
+
|
6
|
+
language: ruby
|
7
|
+
rvm:
|
8
|
+
- 1.9.3
|
9
|
+
- 2.0.0
|
10
|
+
- jruby-19mode
|
11
|
+
- rbx-19mode
|
12
|
+
|
13
|
+
gemfile:
|
14
|
+
- Gemfile
|
15
|
+
- gemfiles/carrierwave-0.8.gemfile
|
16
|
+
- gemfiles/carrierwave-master.gemfile
|
17
|
+
- gemfiles/mongoid-3.0.gemfile
|
18
|
+
- gemfiles/mongoid-3.1.gemfile
|
19
|
+
- gemfiles/mongoid-4.0.gemfile
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,37 +1,66 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/mongoid/mongoid.git
|
3
|
+
revision: 5b0f031992cbec66d68c6cb288a4edb952ed5336
|
4
|
+
branch: master
|
5
|
+
specs:
|
6
|
+
mongoid (4.0.0.beta1)
|
7
|
+
activemodel (>= 4.0.0)
|
8
|
+
moped (~> 2.0.beta6)
|
9
|
+
origin (~> 2.1)
|
10
|
+
tzinfo (>= 0.3.37)
|
11
|
+
|
1
12
|
PATH
|
2
13
|
remote: .
|
3
14
|
specs:
|
4
15
|
glebtv-mongoid-paperclip (0.1.0)
|
16
|
+
mongoid (>= 3.0, < 5.0)
|
5
17
|
paperclip (>= 2.3.6)
|
6
18
|
|
7
19
|
GEM
|
8
20
|
remote: https://rubygems.org/
|
9
21
|
specs:
|
10
|
-
activemodel (4.0.
|
11
|
-
activesupport (= 4.0.
|
22
|
+
activemodel (4.0.2)
|
23
|
+
activesupport (= 4.0.2)
|
12
24
|
builder (~> 3.1.0)
|
13
|
-
activesupport (4.0.
|
25
|
+
activesupport (4.0.2)
|
14
26
|
i18n (~> 0.6, >= 0.6.4)
|
15
27
|
minitest (~> 4.2)
|
16
28
|
multi_json (~> 1.3)
|
17
29
|
thread_safe (~> 0.1)
|
18
30
|
tzinfo (~> 0.3.37)
|
19
31
|
atomic (1.1.14)
|
32
|
+
bson (2.2.0)
|
20
33
|
builder (3.1.4)
|
21
34
|
climate_control (0.0.3)
|
22
35
|
activesupport (>= 3.0)
|
23
|
-
cocaine (0.5.
|
36
|
+
cocaine (0.5.3)
|
24
37
|
climate_control (>= 0.0.3, < 1.0)
|
25
|
-
|
26
|
-
|
38
|
+
connection_pool (1.2.0)
|
39
|
+
diff-lcs (1.2.5)
|
40
|
+
i18n (0.6.9)
|
41
|
+
mime-types (2.1)
|
27
42
|
minitest (4.7.5)
|
28
|
-
|
29
|
-
|
43
|
+
moped (2.0.0.beta6)
|
44
|
+
bson (~> 2.2)
|
45
|
+
connection_pool (~> 1.2)
|
46
|
+
optionable (~> 0.2.0)
|
47
|
+
multi_json (1.8.4)
|
48
|
+
optionable (0.2.0)
|
49
|
+
origin (2.1.0)
|
50
|
+
paperclip (4.0.0)
|
30
51
|
activemodel (>= 3.0.0)
|
31
52
|
activesupport (>= 3.0.0)
|
32
|
-
cocaine (~> 0.5.
|
53
|
+
cocaine (~> 0.5.3)
|
33
54
|
mime-types
|
34
|
-
rake (10.1.
|
55
|
+
rake (10.1.1)
|
56
|
+
rspec (2.14.1)
|
57
|
+
rspec-core (~> 2.14.0)
|
58
|
+
rspec-expectations (~> 2.14.0)
|
59
|
+
rspec-mocks (~> 2.14.0)
|
60
|
+
rspec-core (2.14.7)
|
61
|
+
rspec-expectations (2.14.5)
|
62
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
63
|
+
rspec-mocks (2.14.5)
|
35
64
|
thread_safe (0.1.3)
|
36
65
|
atomic
|
37
66
|
tzinfo (0.3.38)
|
@@ -40,6 +69,8 @@ PLATFORMS
|
|
40
69
|
ruby
|
41
70
|
|
42
71
|
DEPENDENCIES
|
43
|
-
bundler
|
72
|
+
bundler
|
44
73
|
glebtv-mongoid-paperclip!
|
74
|
+
mongoid!
|
45
75
|
rake
|
76
|
+
rspec
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
Mongoid::Paperclip - Making Paperclip play nice with Mongoid ODM
|
2
2
|
================================================================
|
3
3
|
|
4
|
+
## WARN
|
5
|
+
|
6
|
+
.destroy_all on embedded relations DOES NOT WORK, you have to use .destroy
|
7
|
+
|
4
8
|
As the title suggests: `Mongoid::Paperclip` makes it easy to hook up [Paperclip](https://github.com/thoughtbot/paperclip) with [Mongoid](http://mongoid.org/).
|
5
9
|
|
6
10
|
This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
|
@@ -14,7 +18,7 @@ Simply define the `mongoid-paperclip` gem inside your `Gemfile`. Additionally, y
|
|
14
18
|
|
15
19
|
**Rails.root/Gemfile - Just define the following:**
|
16
20
|
|
17
|
-
gem "mongoid-paperclip"
|
21
|
+
gem "glebtv-mongoid-paperclip"
|
18
22
|
gem 'aws-sdk', '~> 1.3.4'
|
19
23
|
|
20
24
|
Next let's assume we have a User model and we want to allow our users to upload an avatar.
|
@@ -18,7 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
20
|
gem.add_dependency 'paperclip', ['>= 2.3.6']
|
21
|
-
gem.
|
21
|
+
gem.add_dependency "mongoid", [">= 3.0", "< 5.0"]
|
22
|
+
gem.add_development_dependency "bundler"
|
23
|
+
gem.add_development_dependency "rspec"
|
22
24
|
gem.add_development_dependency "rake"
|
23
25
|
end
|
24
26
|
|
@@ -1,105 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "mongoid-paperclip/version"
|
4
|
-
|
5
|
-
begin
|
6
|
-
require "paperclip"
|
7
|
-
rescue LoadError
|
8
|
-
puts "Mongoid::Paperclip requires that you install the Paperclip gem."
|
9
|
-
exit
|
10
|
-
end
|
11
|
-
|
12
|
-
##
|
13
|
-
# the id of mongoid is not integer, correct the id_partitioin.
|
14
|
-
Paperclip.interpolates :id_partition do |attachment, style|
|
15
|
-
attachment.instance.id.to_s.scan(/.{4}/).join("/")
|
16
|
-
end
|
17
|
-
|
18
|
-
##
|
19
|
-
# mongoid criteria uses a different syntax.
|
20
|
-
module Paperclip
|
21
|
-
module Helpers
|
22
|
-
def each_instance_with_attachment(klass, name)
|
23
|
-
class_for(klass).unscoped.where("#{name}_file_name".to_sym.ne => nil).each do |instance|
|
24
|
-
yield(instance)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
##
|
31
|
-
# The Mongoid::Paperclip extension
|
32
|
-
# Makes Paperclip play nice with the Mongoid ODM
|
33
|
-
#
|
34
|
-
# Example:
|
35
|
-
#
|
36
|
-
# class User
|
37
|
-
# include Mongoid::Document
|
38
|
-
# include Mongoid::Paperclip
|
39
|
-
#
|
40
|
-
# has_mongoid_attached_file :avatar
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# The above example is all you need to do. This will load the Paperclip library into the User model
|
44
|
-
# and add the "has_mongoid_attached_file" class method. Provide this method with the same values as you would
|
45
|
-
# when using "vanilla Paperclip". The first parameter is a symbol [:field] and the second parameter is a hash of options [options = {}].
|
46
|
-
#
|
47
|
-
# Unlike Paperclip for ActiveRecord, since MongoDB does not use "schema" or "migrations", Mongoid::Paperclip automatically adds the neccesary "fields"
|
48
|
-
# to your Model (MongoDB collection) when you invoke the "#has_mongoid_attached_file" method. When you invoke "has_mongoid_attached_file :avatar" it will
|
49
|
-
# automatially add the following fields:
|
50
|
-
#
|
51
|
-
# field :avatar_file_name, :type => String
|
52
|
-
# field :avatar_content_type, :type => String
|
53
|
-
# field :avatar_file_size, :type => Integer
|
54
|
-
# field :avatar_updated_at, :type => DateTime
|
55
|
-
# field :avatar_fingerprint, :type => String
|
56
|
-
#
|
57
|
-
module Mongoid
|
58
|
-
module Paperclip
|
59
|
-
|
60
|
-
##
|
61
|
-
# Extends the model with the defined Class methods
|
62
|
-
def self.included(base)
|
63
|
-
base.extend(ClassMethods)
|
64
|
-
end
|
65
|
-
|
66
|
-
module ClassMethods
|
67
|
-
|
68
|
-
##
|
69
|
-
# Adds Mongoid::Paperclip's "#has_mongoid_attached_file" class method to the model
|
70
|
-
# which includes Paperclip and Paperclip::Glue in to the model. Additionally
|
71
|
-
# it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't
|
72
|
-
# have migrations.
|
73
|
-
def has_mongoid_attached_file(field, options = {})
|
74
|
-
|
75
|
-
##
|
76
|
-
# Include Paperclip and Paperclip::Glue for compatibility
|
77
|
-
unless self.ancestors.include?(::Paperclip)
|
78
|
-
include ::Paperclip
|
79
|
-
include ::Paperclip::Glue
|
80
|
-
end
|
81
|
-
|
82
|
-
##
|
83
|
-
# Invoke Paperclip's #has_attached_file method and passes in the
|
84
|
-
# arguments specified by the user that invoked Mongoid::Paperclip#has_mongoid_attached_file
|
85
|
-
has_attached_file(field, options)
|
86
|
-
|
87
|
-
##
|
88
|
-
# Define the necessary collection fields in Mongoid for Paperclip
|
89
|
-
field(:"#{field}_file_name", :type => String)
|
90
|
-
field(:"#{field}_content_type", :type => String)
|
91
|
-
field(:"#{field}_file_size", :type => Integer)
|
92
|
-
field(:"#{field}_updated_at", :type => DateTime)
|
93
|
-
field(:"#{field}_fingerprint", :type => String)
|
94
|
-
end
|
95
|
-
|
96
|
-
##
|
97
|
-
# This method is deprecated
|
98
|
-
def has_attached_file(field, options = {})
|
99
|
-
raise "Mongoid::Paperclip#has_attached_file is deprecated, " +
|
100
|
-
"Use 'has_mongoid_attached_file' instead"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
1
|
+
require 'mongoid-paperclip'
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "mongoid-paperclip/version"
|
4
|
+
require "active_support/concern"
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "paperclip"
|
8
|
+
rescue LoadError
|
9
|
+
puts "Mongoid::Paperclip requires that you install the Paperclip gem."
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# the id of mongoid is not integer, correct the id_partitioin.
|
15
|
+
Paperclip.interpolates :id_partition do |attachment, style|
|
16
|
+
attachment.instance.id.to_s.scan(/.{4}/).join("/")
|
17
|
+
end
|
18
|
+
|
19
|
+
Paperclip.interpolates :id_partition_in_8 do |attachment, style|
|
20
|
+
attachment.instance.id.to_s.scan(/.{8}/).join("/")
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# mongoid criteria uses a different syntax.
|
25
|
+
module Paperclip
|
26
|
+
module Helpers
|
27
|
+
# Find all instances of the given Active Record model +klass+ with attachment +name+.
|
28
|
+
# This method is used by the refresh rake tasks.
|
29
|
+
def each_instance_with_attachment(klass, name)
|
30
|
+
if defined?(Mongoid::Document) && class_for(klass) < Mongoid::Document
|
31
|
+
class_for(klass).unscoped.where("#{name}_file_name" => {:$exists => true}).to_a.map do |instance|
|
32
|
+
yield(instance)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
class_for(klass).unscoped.where("#{name}_file_name IS NOT NULL").find_each do |instance|
|
36
|
+
yield(instance)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# The Mongoid::Paperclip extension
|
45
|
+
# Makes Paperclip play nice with the Mongoid ODM
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
#
|
49
|
+
# class User
|
50
|
+
# include Mongoid::Document
|
51
|
+
# include Mongoid::Paperclip
|
52
|
+
#
|
53
|
+
# has_mongoid_attached_file :avatar
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# The above example is all you need to do. This will load the Paperclip library into the User model
|
57
|
+
# and add the "has_mongoid_attached_file" class method. Provide this method with the same values as you would
|
58
|
+
# when using "vanilla Paperclip". The first parameter is a symbol [:field] and the second parameter is a hash of options [options = {}].
|
59
|
+
#
|
60
|
+
# Unlike Paperclip for ActiveRecord, since MongoDB does not use "schema" or "migrations", Mongoid::Paperclip automatically adds the neccesary "fields"
|
61
|
+
# to your Model (MongoDB collection) when you invoke the "#has_mongoid_attached_file" method. When you invoke "has_mongoid_attached_file :avatar" it will
|
62
|
+
# automatially add the following fields:
|
63
|
+
#
|
64
|
+
# field :avatar_file_name, :type => String
|
65
|
+
# field :avatar_content_type, :type => String
|
66
|
+
# field :avatar_file_size, :type => Integer
|
67
|
+
# field :avatar_updated_at, :type => DateTime
|
68
|
+
# field :avatar_fingerprint, :type => String
|
69
|
+
|
70
|
+
module Mongoid
|
71
|
+
module Paperclip
|
72
|
+
extend ActiveSupport::Concern
|
73
|
+
|
74
|
+
module ClassMethods
|
75
|
+
|
76
|
+
# https://github.com/meskyanichi/mongoid-paperclip/pull/45
|
77
|
+
def after_commit(*args, &block)
|
78
|
+
options = args.pop if args.last.is_a? Hash
|
79
|
+
if options
|
80
|
+
case options[:on]
|
81
|
+
when :create
|
82
|
+
after_create(*args, &block)
|
83
|
+
when :update
|
84
|
+
after_update(*args, &block)
|
85
|
+
when :destroy
|
86
|
+
after_destroy(*args, &block)
|
87
|
+
else
|
88
|
+
after_save(*args, &block)
|
89
|
+
end
|
90
|
+
else
|
91
|
+
after_save(*args, &block)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Adds Mongoid::Paperclip's "#has_mongoid_attached_file" class method to the model
|
96
|
+
# which includes Paperclip and Paperclip::Glue in to the model. Additionally
|
97
|
+
# it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't
|
98
|
+
# have migrations.
|
99
|
+
def has_mongoid_attached_file(field_name, options = {})
|
100
|
+
# Include Paperclip and Paperclip::Glue for compatibility
|
101
|
+
unless self.ancestors.include?(::Paperclip)
|
102
|
+
include ::Paperclip
|
103
|
+
include ::Paperclip::Glue
|
104
|
+
end
|
105
|
+
|
106
|
+
# Invoke Paperclip's #has_attached_file method and passes in the
|
107
|
+
# arguments specified by the user that invoked Mongoid::Paperclip#has_mongoid_attached_file
|
108
|
+
has_attached_file(field_name, options)
|
109
|
+
|
110
|
+
# Define the necessary collection fields in Mongoid for Paperclip
|
111
|
+
field :"#{field_name}_file_name", type: String, default: nil
|
112
|
+
field :"#{field_name}_content_type", type: String, default: nil
|
113
|
+
field :"#{field_name}_file_size", type: Integer, default: nil
|
114
|
+
field :"#{field_name}_updated_at", type: Time, default: nil
|
115
|
+
field :"#{field_name}_fingerprint", type: String, default: nil
|
116
|
+
|
117
|
+
# convenience attr (RailsAdmin uses this naming)
|
118
|
+
attr_accessor :"delete_#{field_name}"
|
119
|
+
before_validation do
|
120
|
+
self.send(field).clear if self.send(:"delete_#{field_name}").present?
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe 'Normal' do
|
4
|
+
it 'saves file' do
|
5
|
+
t = MyTest.create!(test: @file)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Embedded' do
|
10
|
+
it 'deletion works wo paperclip' do
|
11
|
+
pr = MyTest.create!
|
12
|
+
2.times do |t|
|
13
|
+
pr.examples.create!(name: t.to_s)
|
14
|
+
end
|
15
|
+
pr.examples.length.should eq 2
|
16
|
+
pr.examples.destroy_all
|
17
|
+
pr.reload
|
18
|
+
pr.examples.length.should eq 0
|
19
|
+
MyTest.destroy_all
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'deletion works with ts' do
|
23
|
+
pr = MyTest.create!
|
24
|
+
2.times do |t|
|
25
|
+
pr.t_tests.create!
|
26
|
+
end
|
27
|
+
pr.t_tests.length.should eq 2
|
28
|
+
pr.t_tests.destroy_all.should eq 2
|
29
|
+
pr.reload
|
30
|
+
pr.t_tests.length.should eq 0
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'deletion works' do
|
34
|
+
pr = MyTest.create!
|
35
|
+
2.times do |t|
|
36
|
+
pr.examples.create!(name: t.to_s, test: @file)
|
37
|
+
end
|
38
|
+
pr.examples.length.should eq 2
|
39
|
+
pr.examples.destroy.should eq 2
|
40
|
+
pr.examples.length.should eq 0
|
41
|
+
pr.reload
|
42
|
+
pr.examples.length.should eq 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'deletion works' do
|
46
|
+
pr = MyTest.create!
|
47
|
+
2.times do |t|
|
48
|
+
pr.examples.create!(name: t.to_s, test: @file)
|
49
|
+
end
|
50
|
+
pr.examples.first.destroy
|
51
|
+
pr.reload
|
52
|
+
pr.examples.length.should eq 1
|
53
|
+
end
|
54
|
+
|
55
|
+
pending 'deletion works' do
|
56
|
+
pr = MyTest.create!
|
57
|
+
2.times do |t|
|
58
|
+
pr.examples.create!(name: t.to_s, test: @file)
|
59
|
+
end
|
60
|
+
pr.examples.destroy_all.should eq 2
|
61
|
+
pr.reload
|
62
|
+
pr.examples.length.should eq 1
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
ROOT = File.join(File.dirname(__FILE__), "..")
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift(File.join(ROOT, "lib"))
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
require "rspec"
|
7
|
+
require "mongoid"
|
8
|
+
require "mongoid-paperclip"
|
9
|
+
|
10
|
+
Paperclip::Attachment.default_options.merge!({
|
11
|
+
path: "#{ROOT}/tmp/:attachment/:id/:style/:filename",
|
12
|
+
url: "/tmp/:attachment/:id/:style/:filename"
|
13
|
+
})
|
14
|
+
|
15
|
+
Mongoid.configure do |config|
|
16
|
+
config.connect_to "mongoid-paperclip"
|
17
|
+
end
|
18
|
+
Paperclip.options[:log] = false
|
19
|
+
|
20
|
+
#Mongoid.logger = Logger.new($stdout)
|
21
|
+
#Moped.logger = Logger.new($stdout)
|
22
|
+
#Moped.logger.level = Logger::DEBUG
|
23
|
+
|
24
|
+
class MyTest
|
25
|
+
include Mongoid::Document
|
26
|
+
include Mongoid::Paperclip
|
27
|
+
has_mongoid_attached_file :test
|
28
|
+
validates_attachment_content_type :test, :content_type => ['image/gif']
|
29
|
+
|
30
|
+
embeds_many :examples
|
31
|
+
embeds_many :t_tests
|
32
|
+
end
|
33
|
+
|
34
|
+
class TTest
|
35
|
+
include Mongoid::Document
|
36
|
+
include Mongoid::Timestamps::Short
|
37
|
+
embedded_in :my_test
|
38
|
+
end
|
39
|
+
|
40
|
+
class Example
|
41
|
+
include Mongoid::Document
|
42
|
+
include Mongoid::Paperclip
|
43
|
+
embedded_in :my_test
|
44
|
+
field :name
|
45
|
+
has_mongoid_attached_file :test
|
46
|
+
do_not_validate_attachment_file_type :test
|
47
|
+
end
|
48
|
+
|
49
|
+
RSpec.configure do |config|
|
50
|
+
config.before(:all) do
|
51
|
+
@file = File.open(File.join(File.dirname(__FILE__), "support", '1024x768.gif'))
|
52
|
+
end
|
53
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glebtv-mongoid-paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GlebTV
|
@@ -9,48 +9,82 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 2.3.6
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 2.3.6
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mongoid
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.0'
|
35
|
+
- - <
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '5.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.0'
|
45
|
+
- - <
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
28
48
|
- !ruby/object:Gem::Dependency
|
29
49
|
name: bundler
|
30
50
|
requirement: !ruby/object:Gem::Requirement
|
31
51
|
requirements:
|
32
|
-
- -
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
33
67
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
68
|
+
version: '0'
|
35
69
|
type: :development
|
36
70
|
prerelease: false
|
37
71
|
version_requirements: !ruby/object:Gem::Requirement
|
38
72
|
requirements:
|
39
|
-
- -
|
73
|
+
- - '>='
|
40
74
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
75
|
+
version: '0'
|
42
76
|
- !ruby/object:Gem::Dependency
|
43
77
|
name: rake
|
44
78
|
requirement: !ruby/object:Gem::Requirement
|
45
79
|
requirements:
|
46
|
-
- -
|
80
|
+
- - '>='
|
47
81
|
- !ruby/object:Gem::Version
|
48
82
|
version: '0'
|
49
83
|
type: :development
|
50
84
|
prerelease: false
|
51
85
|
version_requirements: !ruby/object:Gem::Requirement
|
52
86
|
requirements:
|
53
|
-
- -
|
87
|
+
- - '>='
|
54
88
|
- !ruby/object:Gem::Version
|
55
89
|
version: '0'
|
56
90
|
description: Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM
|
@@ -63,14 +97,21 @@ files:
|
|
63
97
|
- .gitignore
|
64
98
|
- .ruby-gemset
|
65
99
|
- .ruby-version
|
100
|
+
- .travis.yml
|
66
101
|
- Gemfile
|
67
102
|
- Gemfile.lock
|
68
103
|
- LICENSE
|
69
104
|
- README.md
|
70
105
|
- Rakefile
|
106
|
+
- gemfiles/mongoid-3.1.gemfile
|
107
|
+
- gemfiles/mongoid-4.0.gemfile
|
71
108
|
- glebtv-mongoid-paperclip.gemspec
|
72
109
|
- lib/glebtv-mongoid-paperclip.rb
|
110
|
+
- lib/mongoid-paperclip.rb
|
73
111
|
- lib/mongoid-paperclip/version.rb
|
112
|
+
- spec/mongoid_paperclip_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/support/1024x768.gif
|
74
115
|
homepage: https://github.com/glebtv/mongoid-paperclip
|
75
116
|
licenses: []
|
76
117
|
metadata: {}
|
@@ -80,17 +121,17 @@ require_paths:
|
|
80
121
|
- lib
|
81
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
123
|
requirements:
|
83
|
-
- -
|
124
|
+
- - '>='
|
84
125
|
- !ruby/object:Gem::Version
|
85
126
|
version: '0'
|
86
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
128
|
requirements:
|
88
|
-
- -
|
129
|
+
- - '>='
|
89
130
|
- !ruby/object:Gem::Version
|
90
131
|
version: '0'
|
91
132
|
requirements: []
|
92
133
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.2.1
|
94
135
|
signing_key:
|
95
136
|
specification_version: 4
|
96
137
|
summary: Fork of Mongoid::Paperclip
|