public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
welcome, AttachmentFu::Tasks
technoweenie (author)
Sat Mar 15 16:57:36 -0700 2008
commit  79da060e327dbff5ba7cf430d1cd295dd0612bce
tree    5ef09dd700d1108017853920b02028115aeeac78
parent  d1e8baf83d541db47552df55fa5dc8de450adf11
...
18
19
20
21
 
22
23
24
...
18
19
20
 
21
22
23
24
0
@@ -18,7 +18,7 @@ desc "Run all examples with RCov"
0
 Spec::Rake::SpecTask.new(:rcov) do |t|
0
   t.spec_files = FileList['spec/**/*.rb']
0
   t.rcov = true
0
- t.rcov_opts = ['--exclude', 'spec']
0
+ t.rcov_opts = %w(--exclude spec --exclude activesupport --exclude activerecord)
0
   t.rcov_dir = "doc/rcov"
0
 end
0
 
...
25
26
27
28
29
 
30
31
32
...
35
36
37
38
39
 
 
40
41
42
...
25
26
27
 
 
28
29
30
31
...
34
35
36
 
 
37
38
39
40
41
0
@@ -25,8 +25,7 @@ module AttachmentFu
0
         include AttachmentFu
0
         self.root_path = options[:root] || root_path || AttachmentFu.root_path
0
         self.attachment_path = options[:path] || attachment_path || File.join("public", table_name)
0
- self.attachment_tasks
0
- attachment_tasks.instance_eval &block if block
0
+ self.attachment_tasks(&block)
0
       end
0
     end
0
   end
0
@@ -35,8 +34,8 @@ module AttachmentFu
0
     class << base
0
       attr_writer :attachment_tasks
0
       
0
- def attachment_tasks
0
- @attachment_tasks ||= superclass.respond_to?(:attachment_tasks) ? superclass.attachment_tasks.dup : AttachmentFu::Tasks.new(self)
0
+ def attachment_tasks(&block)
0
+ @attachment_tasks ||= superclass.respond_to?(:attachment_tasks) ? superclass.attachment_tasks.copy(&block) : AttachmentFu::Tasks.new(self, &block)
0
       end
0
     end
0
     base.send :attr_reader, :temp_path
...
1
2
 
 
 
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
 
 
 
 
 
 
7
8
9
10
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
 
30
31
32
33
34
35
36
37
38
39
0
@@ -1,9 +1,38 @@
0
 module AttachmentFu
0
   class Tasks
0
+ def self.all
0
+ @all ||= {}
0
+ end
0
+
0
+ def self.[](key)
0
+ all[key]
0
+ end
0
+
0
     attr_reader :klass
0
+ attr_reader :stack
0
+ attr_reader :all
0
+
0
+ def initialize(klass, stack = [], all = {}, &block)
0
+ @klass, @stack, @all = klass, stack, all
0
+ instance_eval(&block) if block
0
+ end
0
+
0
+ def copy(&block)
0
+ self.class.new(@klass, @stack.dup, @all.dup, &block)
0
+ end
0
+
0
+ def task(key, options = {})
0
+ t = self.class[key]
0
+ @stack << [t, options]
0
+ @all[key] = t
0
+ end
0
     
0
- def initialize(klass)
0
- @klass = klass
0
+ def [](key_or_index)
0
+ case key_or_index
0
+ when Symbol then @all[key_or_index]
0
+ when Fixnum then @stack[key_or_index]
0
+ else raise(ArgumentError, "Invalid Key: #{key_or_index.inspect}")
0
+ end
0
     end
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.