jamieorc-joint 0.5.6 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.3', :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,34 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joint (0.5.6)
4
+ joint (0.6.1)
5
5
  mime-types
6
- mongo_mapper (~> 0.8.6)
6
+ mongo_mapper (~> 0.9)
7
7
  wand (~> 0.4)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activesupport (3.0.3)
12
+ activemodel (3.1.3)
13
+ activesupport (= 3.1.3)
14
+ builder (~> 3.0.0)
15
+ i18n (~> 0.6)
16
+ activesupport (3.1.3)
17
+ multi_json (~> 1.0)
13
18
  bson (1.3.1)
14
19
  bson_ext (1.3.1)
15
- i18n (0.4.2)
20
+ builder (3.0.0)
21
+ i18n (0.6.0)
16
22
  jnunemaker-matchy (0.4.0)
17
- jnunemaker-validatable (1.8.4)
18
- activesupport (>= 2.3.4)
19
- mime-types (1.16)
23
+ mime-types (1.17.2)
20
24
  mocha (0.9.10)
21
25
  rake
22
26
  mongo (1.3.1)
23
27
  bson (>= 1.3.1)
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_mapper (0.10.1)
29
+ activemodel (~> 3.0)
30
+ activesupport (~> 3.0)
31
+ plucky (~> 0.4.0)
32
+ multi_json (1.0.3)
33
+ plucky (0.4.3)
34
+ mongo (~> 1.3)
30
35
  rake (0.8.7)
31
- safe_shell (1.0.0)
36
+ safe_shell (1.0.1)
32
37
  shoulda (2.11.3)
33
38
  wand (0.4)
34
39
  mime-types
@@ -38,12 +43,8 @@ PLATFORMS
38
43
  ruby
39
44
 
40
45
  DEPENDENCIES
41
- bson_ext (~> 1.3)
42
- i18n (= 0.4.2)
46
+ bson_ext
43
47
  jnunemaker-matchy
44
48
  joint!
45
- mime-types
46
49
  mocha
47
- mongo_mapper (~> 0.8.6)
48
50
  shoulda
49
- wand (~> 0.4)
data/joint.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/joint/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "jamieorc-joint"
6
6
  s.summary = %Q{MongoMapper and GridFS joined in file upload love.}
7
- s.description = %Q{MongoMapper and GridFS joined in file upload love.}
7
+ s.description = %Q{MongoMapper and GridFS joined in file upload love. Updates by Jamie for EmbeddedDocument.}
8
8
  s.email = "jamieorc@gmail.com"
9
9
  s.homepage = "http://github.com/jamieorc/joint"
10
10
  s.authors = ["John Nunemaker", "Jamie Orchard-Hays"]
@@ -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'
20
16
 
21
17
  s.files = `git ls-files`.split("\n")
22
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -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
  before_save :nullify_nil_attachments_attributes
@@ -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.6'
2
+ Version = '0.6.1'
3
3
  end
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)
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'
@@ -78,7 +81,9 @@ module JointTestHelpers
78
81
  end
79
82
 
80
83
  def open_file(name)
81
- File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
84
+ f = File.open(File.join(File.dirname(__FILE__), 'fixtures', name), 'r')
85
+ f.binmode
86
+ f
82
87
  end
83
88
 
84
89
  def grid
data/test/test_joint.rb CHANGED
@@ -157,9 +157,9 @@ class JointTest < Test::Unit::TestCase
157
157
  subject.file?.should be(true)
158
158
  end
159
159
 
160
- should "respond with false when asked if the attachment is nil?" do
161
- subject.image.nil?.should be(false)
162
- subject.file.nil?.should be(false)
160
+ should "respond with false when asked if the attachment is blank?" do
161
+ subject.image.blank?.should be(false)
162
+ subject.file.blank?.should be(false)
163
163
  end
164
164
 
165
165
  should "clear assigned attachments so they don't get uploaded twice" do
@@ -232,9 +232,9 @@ class JointTest < Test::Unit::TestCase
232
232
  subject.file?.should be(true)
233
233
  end
234
234
 
235
- should "respond with false when asked if the attachment is nil?" do
236
- subject.image.nil?.should be(false)
237
- subject.file.nil?.should be(false)
235
+ should "respond with false when asked if the attachment is blank?" do
236
+ subject.image.blank?.should be(false)
237
+ subject.file.blank?.should be(false)
238
238
  end
239
239
 
240
240
  should "clear assigned attachments so they don't get uploaded twice" do
@@ -242,7 +242,6 @@ class JointTest < Test::Unit::TestCase
242
242
  subject.save
243
243
  end
244
244
  end
245
-
246
245
 
247
246
  context "Updating existing attachment" do
248
247
  setup do
@@ -378,6 +377,11 @@ class JointTest < Test::Unit::TestCase
378
377
  subject.image.nil?.should be(true)
379
378
  end
380
379
 
380
+ should "respond with true when asked if the attachment is blank?" do
381
+ subject.image = nil
382
+ subject.image.blank?.should be(true)
383
+ end
384
+
381
385
  should "clear nil attachments after save and not attempt to delete again" do
382
386
  Mongo::Grid.any_instance.expects(:delete).once
383
387
  subject.image = nil
@@ -424,6 +428,11 @@ class JointTest < Test::Unit::TestCase
424
428
  subject.image = nil
425
429
  subject.image.nil?.should be(true)
426
430
  end
431
+
432
+ should "respond with true when asked if the attachment is blank?" do
433
+ subject.image = nil
434
+ subject.image.blank?.should be(true)
435
+ end
427
436
 
428
437
  should "clear nil attachments after save and not attempt to delete again" do
429
438
  Mongo::Grid.any_instance.expects(:delete).once
@@ -516,6 +525,8 @@ class JointTest < Test::Unit::TestCase
516
525
  include MongoMapper::Document
517
526
  plugin Joint
518
527
  attachment :file, :required => true
528
+
529
+ def self.name; "Foo"; end
519
530
  end
520
531
  end
521
532
 
@@ -539,15 +550,14 @@ class JointTest < Test::Unit::TestCase
539
550
  io = Joint::IO.new({
540
551
  :name => 'foo.txt',
541
552
  :type => 'plain/text',
542
- :content => 'This is my stuff',
543
- :size => 19,
553
+ :content => 'This is my stuff'
544
554
  })
545
555
  @asset = Asset.create(:file => io)
546
556
  end
547
557
 
548
558
  should "work" do
549
559
  @asset.file_name.should == 'foo.txt'
550
- @asset.file_size.should == 19
560
+ @asset.file_size.should == 16
551
561
  @asset.file_type.should == 'plain/text'
552
562
  @asset.file.read.should == 'This is my stuff'
553
563
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamieorc-joint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
8
  - 6
10
- version: 0.5.6
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Nunemaker
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-23 00:00:00 -05:00
20
- default_executable:
19
+ date: 2011-11-23 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: wand
@@ -56,57 +55,14 @@ dependencies:
56
55
  requirements:
57
56
  - - ~>
58
57
  - !ruby/object:Gem::Version
59
- hash: 51
58
+ hash: 25
60
59
  segments:
61
60
  - 0
62
- - 8
63
- - 6
64
- version: 0.8.6
61
+ - 9
62
+ version: "0.9"
65
63
  type: :runtime
66
64
  version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: shoulda
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
79
- type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: mocha
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- name: jnunemaker-matchy
97
- prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- type: :development
108
- version_requirements: *id006
109
- description: MongoMapper and GridFS joined in file upload love.
65
+ description: MongoMapper and GridFS joined in file upload love. Updates by Jamie for EmbeddedDocument.
110
66
  email: jamieorc@gmail.com
111
67
  executables: []
112
68
 
@@ -139,7 +95,6 @@ files:
139
95
  - test/helper.rb
140
96
  - test/joint/test_io.rb
141
97
  - test/test_joint.rb
142
- has_rdoc: true
143
98
  homepage: http://github.com/jamieorc/joint
144
99
  licenses: []
145
100
 
@@ -169,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
124
  requirements: []
170
125
 
171
126
  rubyforge_project:
172
- rubygems_version: 1.5.2
127
+ rubygems_version: 1.8.10
173
128
  signing_key:
174
129
  specification_version: 3
175
130
  summary: MongoMapper and GridFS joined in file upload love.