joint 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,9 +8,14 @@ module Joint
8
8
  def self.configure(model)
9
9
  model.class_inheritable_accessor :attachment_names
10
10
  model.attachment_names = Set.new
11
+ model.send(:include, model.attachment_accessor_module)
11
12
  end
12
13
 
13
14
  module ClassMethods
15
+ def attachment_accessor_module
16
+ @attachment_accessor_module ||= Module.new
17
+ end
18
+
14
19
  def attachment(name, options = {})
15
20
  options.symbolize_keys!
16
21
  name = name.to_sym
@@ -21,20 +26,20 @@ module Joint
21
26
  after_save :destroy_nil_attachments
22
27
  before_destroy :destroy_all_attachments
23
28
 
24
- key "#{name}_id".to_sym, ObjectId
25
- key "#{name}_name".to_sym, String
26
- key "#{name}_size".to_sym, Integer
27
- key "#{name}_type".to_sym, String
29
+ key :"#{name}_id", ObjectId
30
+ key :"#{name}_name", String
31
+ key :"#{name}_size", Integer
32
+ key :"#{name}_type", String
28
33
 
29
34
  validates_presence_of(name) if options[:required]
30
35
 
31
- class_eval <<-EOC
36
+ attachment_accessor_module.module_eval <<-EOC
32
37
  def #{name}
33
38
  @#{name} ||= AttachmentProxy.new(self, :#{name})
34
39
  end
35
40
 
36
41
  def #{name}?
37
- !nil_attachments.include?(:#{name}) && self.send(:#{name}_id?)
42
+ !nil_attachments.include?(:#{name}) && send(:#{name}_id?)
38
43
  end
39
44
 
40
45
  def #{name}=(file)
@@ -42,10 +47,10 @@ module Joint
42
47
  nil_attachments << :#{name}
43
48
  assigned_attachments.delete(:#{name})
44
49
  else
45
- self["#{name}_id"] = BSON::ObjectId.new if self["#{name}_id"].nil?
46
- self["#{name}_size"] = File.size(file)
47
- self["#{name}_type"] = Wand.wave(file.path)
48
- self["#{name}_name"] = Joint.file_name(file)
50
+ send("#{name}_id=", BSON::ObjectId.new) if send("#{name}_id").nil?
51
+ send("#{name}_size=", File.size(file))
52
+ send("#{name}_type=", Wand.wave(file.path))
53
+ send("#{name}_name=", Joint.file_name(file))
49
54
  assigned_attachments[:#{name}] = file
50
55
  nil_attachments.delete(:#{name})
51
56
  end
@@ -1,3 +1,3 @@
1
1
  module Joint
2
- Version = '0.4'
2
+ Version = '0.5'
3
3
  end
@@ -34,7 +34,7 @@ module JointTestHelpers
34
34
  def grid
35
35
  @grid ||= Mongo::Grid.new(MongoMapper.database)
36
36
  end
37
-
37
+
38
38
  def key_names
39
39
  [:id, :name, :type, :size]
40
40
  end
@@ -68,6 +68,10 @@ class JointTest < Test::Unit::TestCase
68
68
  end
69
69
  end
70
70
 
71
+ should "add memoized accessors module" do
72
+ Asset.attachment_accessor_module.should be_instance_of(Module)
73
+ end
74
+
71
75
  context "with inheritance" do
72
76
  should "add attachment to attachment_names" do
73
77
  BaseModel.attachment_names.should == Set.new([:file])
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- version: "0.4"
8
+ - 5
9
+ version: "0.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-07 00:00:00 -04:00
17
+ date: 2010-12-06 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  hash: 21
29
29
  segments:
@@ -53,14 +53,14 @@ dependencies:
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
- - - ">="
56
+ - - ~>
57
57
  - !ruby/object:Gem::Version
58
- hash: 11
58
+ hash: 51
59
59
  segments:
60
60
  - 0
61
- - 7
62
- - 4
63
- version: 0.7.4
61
+ - 8
62
+ - 6
63
+ version: 0.8.6
64
64
  type: :runtime
65
65
  version_requirements: *id003
66
66
  - !ruby/object:Gem::Dependency