joint 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,8 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- gem 'i18n', '0.4.2'
4
- gem 'bson_ext', '~> 1.1', :require => false
5
- gemspec
3
+ gemspec
4
+
5
+ gem 'bson_ext', :require => false
6
+ gem 'shoulda'
7
+ gem 'mocha'
8
+ gem 'jnunemaker-matchy'
data/Gemfile.lock CHANGED
@@ -1,32 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joint (0.5.2)
4
+ joint (0.6.0)
5
5
  mime-types
6
- mongo_mapper (~> 0.8.6)
6
+ mongo_mapper (~> 0.9.0)
7
7
  wand (~> 0.4)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activesupport (3.0.3)
13
- bson (1.1.5)
14
- bson_ext (1.1.5)
15
- i18n (0.4.2)
12
+ activemodel (3.1.0)
13
+ activesupport (= 3.1.0)
14
+ bcrypt-ruby (~> 3.0.0)
15
+ builder (~> 3.0.0)
16
+ i18n (~> 0.6)
17
+ activesupport (3.1.0)
18
+ multi_json (~> 1.0)
19
+ bcrypt-ruby (3.0.1)
20
+ bson (1.3.1)
21
+ bson_ext (1.3.1)
22
+ builder (3.0.0)
23
+ i18n (0.6.0)
16
24
  jnunemaker-matchy (0.4.0)
17
- jnunemaker-validatable (1.8.4)
18
- activesupport (>= 2.3.4)
19
25
  mime-types (1.16)
20
26
  mocha (0.9.10)
21
27
  rake
22
- mongo (1.1.5)
23
- bson (>= 1.1.5)
24
- mongo_mapper (0.8.6)
25
- activesupport (>= 2.3.4)
26
- jnunemaker-validatable (~> 1.8.4)
27
- plucky (~> 0.3.6)
28
- plucky (0.3.6)
29
- mongo (~> 1.1)
28
+ mongo (1.3.1)
29
+ bson (>= 1.3.1)
30
+ mongo_mapper (0.9.2)
31
+ activemodel (~> 3.0)
32
+ activesupport (~> 3.0)
33
+ plucky (~> 0.3.8)
34
+ multi_json (1.0.2)
35
+ plucky (0.3.8)
36
+ mongo (~> 1.3)
30
37
  rake (0.8.7)
31
38
  safe_shell (1.0.0)
32
39
  shoulda (2.11.3)
@@ -38,12 +45,8 @@ PLATFORMS
38
45
  ruby
39
46
 
40
47
  DEPENDENCIES
41
- bson_ext (~> 1.1)
42
- i18n (= 0.4.2)
48
+ bson_ext
43
49
  jnunemaker-matchy
44
50
  joint!
45
- mime-types
46
51
  mocha
47
- mongo_mapper (~> 0.8.6)
48
52
  shoulda
49
- wand (~> 0.4)
data/joint.gemspec CHANGED
@@ -12,11 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.add_dependency 'wand', '~> 0.4'
14
14
  s.add_dependency 'mime-types'
15
- s.add_dependency 'mongo_mapper', '~> 0.8.6'
16
-
17
- s.add_development_dependency 'shoulda'
18
- s.add_development_dependency 'mocha'
19
- s.add_development_dependency 'jnunemaker-matchy'
15
+ s.add_dependency 'mongo_mapper', '~> 0.9.0'
20
16
 
21
17
  s.files = `git ls-files`.split("\n")
22
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/joint.rb CHANGED
@@ -3,10 +3,12 @@ require 'mime/types'
3
3
  require 'wand'
4
4
 
5
5
  module Joint
6
- def self.configure(model)
7
- model.class_inheritable_accessor :attachment_names
8
- model.attachment_names = Set.new
9
- model.send(:include, model.attachment_accessor_module)
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ class_attribute :attachment_names
10
+ self.attachment_names = Set.new
11
+ include attachment_accessor_module
10
12
  end
11
13
 
12
14
  def self.name(file)
@@ -23,6 +23,7 @@ module Joint
23
23
  def nil?
24
24
  !@instance.send("#{@name}?")
25
25
  end
26
+ alias_method :blank?, :nil?
26
27
 
27
28
  def grid_io
28
29
  @grid_io ||= @instance.grid.get(id)
@@ -8,7 +8,7 @@ module Joint
8
8
  options.symbolize_keys!
9
9
  name = name.to_sym
10
10
 
11
- self.attachment_names << name
11
+ self.attachment_names = attachment_names.dup.add(name)
12
12
 
13
13
  after_save :save_attachments
14
14
  after_save :destroy_nil_attachments
@@ -19,7 +19,7 @@ module Joint
19
19
  next unless io.respond_to?(:read)
20
20
  io.rewind if io.respond_to?(:rewind)
21
21
  grid.delete(send(name).id)
22
- grid.put(io.read, {
22
+ grid.put(io, {
23
23
  :_id => send(name).id,
24
24
  :filename => send(name).name,
25
25
  :content_type => send(name).type,
data/lib/joint/io.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'stringio'
2
+
1
3
  module Joint
2
4
  class IO
3
5
  attr_accessor :name, :content, :type, :size
@@ -5,10 +7,17 @@ module Joint
5
7
  def initialize(attrs={})
6
8
  attrs.each { |key, value| send("#{key}=", value) }
7
9
  @type ||= 'plain/text'
8
- @size ||= @content.size unless @content.nil?
10
+ end
11
+
12
+ def content=(value)
13
+ @io = StringIO.new(value || nil)
14
+ @size = value ? value.size : 0
15
+ end
16
+
17
+ def read(*args)
18
+ @io.read(*args)
9
19
  end
10
20
 
11
21
  alias path name
12
- alias read content
13
22
  end
14
23
  end
data/lib/joint/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Joint
2
- Version = '0.5.5'
2
+ Version = '0.6.0'
3
3
  end
data/test/helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup(:default, 'test', 'development')
3
+
1
4
  require 'tempfile'
2
5
  require 'pp'
3
6
  require 'shoulda'
@@ -67,7 +70,9 @@ module JointTestHelpers
67
70
  end
68
71
 
69
72
  def open_file(name)
70
- File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
73
+ f = File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
74
+ f.binmode
75
+ f
71
76
  end
72
77
 
73
78
  def grid
data/test/test_joint.rb CHANGED
@@ -158,6 +158,11 @@ class JointTest < Test::Unit::TestCase
158
158
  subject.file.nil?.should be(false)
159
159
  end
160
160
 
161
+ should "respond with false when asked if the attachment is blank?" do
162
+ subject.image.blank?.should be(false)
163
+ subject.file.blank?.should be(false)
164
+ end
165
+
161
166
  should "clear assigned attachments so they don't get uploaded twice" do
162
167
  Mongo::Grid.any_instance.expects(:put).never
163
168
  subject.save
@@ -247,6 +252,11 @@ class JointTest < Test::Unit::TestCase
247
252
  subject.image.nil?.should be(true)
248
253
  end
249
254
 
255
+ should "respond with true when asked if the attachment is blank?" do
256
+ subject.image = nil
257
+ subject.image.blank?.should be(true)
258
+ end
259
+
250
260
  should "clear nil attachments after save and not attempt to delete again" do
251
261
  Mongo::Grid.any_instance.expects(:delete).once
252
262
  subject.image = nil
@@ -323,6 +333,8 @@ class JointTest < Test::Unit::TestCase
323
333
  include MongoMapper::Document
324
334
  plugin Joint
325
335
  attachment :file, :required => true
336
+
337
+ def self.name; "Foo"; end
326
338
  end
327
339
  end
328
340
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 5
10
- version: 0.5.5
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Nunemaker
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-22 00:00:00 -05:00
19
- default_executable:
18
+ date: 2011-09-14 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: wand
@@ -55,56 +54,14 @@ dependencies:
55
54
  requirements:
56
55
  - - ~>
57
56
  - !ruby/object:Gem::Version
58
- hash: 51
57
+ hash: 59
59
58
  segments:
60
59
  - 0
61
- - 8
62
- - 6
63
- version: 0.8.6
60
+ - 9
61
+ - 0
62
+ version: 0.9.0
64
63
  type: :runtime
65
64
  version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: shoulda
68
- prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
78
- type: :development
79
- version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: mocha
82
- prerelease: false
83
- requirement: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
92
- type: :development
93
- version_requirements: *id005
94
- - !ruby/object:Gem::Dependency
95
- name: jnunemaker-matchy
96
- prerelease: false
97
- requirement: &id006 !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
106
- type: :development
107
- version_requirements: *id006
108
65
  description: MongoMapper and GridFS joined in file upload love.
109
66
  email: nunemaker@gmail.com
110
67
  executables: []
@@ -138,7 +95,6 @@ files:
138
95
  - test/helper.rb
139
96
  - test/joint/test_io.rb
140
97
  - test/test_joint.rb
141
- has_rdoc: true
142
98
  homepage: http://github.com/jnunemaker/joint
143
99
  licenses: []
144
100
 
@@ -168,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
124
  requirements: []
169
125
 
170
126
  rubyforge_project:
171
- rubygems_version: 1.3.7
127
+ rubygems_version: 1.8.9
172
128
  signing_key:
173
129
  specification_version: 3
174
130
  summary: MongoMapper and GridFS joined in file upload love.