bulldog 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.0.9 2009-11-18
2
+
3
+ * Allow specifying a subset of styles to process via a :styles option
4
+ to #process.
5
+
1
6
  == 0.0.8 2009-11-18
2
7
 
3
8
  * Fix invocations of ffmpeg over multiple styles.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bulldog}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["George Ogata"]
12
- s.date = %q{2009-11-18}
12
+ s.date = %q{2009-11-23}
13
13
  s.description = %q{= Bulldog
14
14
 
15
15
  Flexible file attachments for active record.
@@ -23,15 +23,18 @@ module Bulldog
23
23
  #
24
24
  # Return true if no errors were encountered, false otherwise.
25
25
  #
26
- def process(event_name)
26
+ def process(event_name, options={})
27
27
  reflection.events[event_name].each do |event|
28
28
  if (types = event.attachment_types)
29
29
  next unless types.include?(type)
30
30
  end
31
31
  processor_type = event.processor_type || default_processor_type
32
32
  processor_class = Processor.const_get(processor_type.to_s.camelize)
33
- processor = processor_class.new(self, styles_for_event(event), stream.path)
34
- processor.process(&event.callback)
33
+ processor = processor_class.new(self, stream.path)
34
+ styles = reflection.styles
35
+ names = options[:styles] || event.styles and
36
+ styles = reflection.styles.slice(*names)
37
+ processor.process(styles, options, &event.callback)
35
38
  end
36
39
  record.errors.empty?
37
40
  end
@@ -144,14 +147,6 @@ module Bulldog
144
147
 
145
148
  private # -------------------------------------------------------
146
149
 
147
- def styles_for_event(event)
148
- if event.styles
149
- styles = reflection.styles.slice(*event.styles)
150
- else
151
- styles = reflection.styles
152
- end
153
- end
154
-
155
150
  #
156
151
  # Remove the files for this attachment, along with any parent
157
152
  # directories.
@@ -1,9 +1,8 @@
1
1
  module Bulldog
2
2
  module Processor
3
3
  class Base
4
- def initialize(attachment, styles, input_file)
4
+ def initialize(attachment, input_file)
5
5
  @attachment = attachment
6
- @styles = styles
7
6
  @input_file = input_file
8
7
  end
9
8
 
@@ -61,8 +60,13 @@ module Bulldog
61
60
  # #style will be set to the current style each time the block is
62
61
  # called.
63
62
  #
64
- def process(&block)
65
- return if styles.empty?
63
+ # Return true if any styles were processed, false otherwise.
64
+ # Subclasses can use this to determine if any processing
65
+ # commands need to be run.
66
+ #
67
+ def process(styles, options={}, &block)
68
+ @styles = styles
69
+ return false if styles.empty?
66
70
  styles.each do |style|
67
71
  @style = style
68
72
  begin
@@ -71,6 +75,7 @@ module Bulldog
71
75
  @style = nil
72
76
  end
73
77
  end
78
+ true
74
79
  end
75
80
 
76
81
  #
@@ -7,21 +7,21 @@ module Bulldog
7
7
 
8
8
  def initialize(*args)
9
9
  super
10
- @arguments = style_list_map
11
- @still_frame_callbacks = style_list_map
12
10
  end
13
11
 
14
- def process
15
- return if styles.empty?
16
- super
17
- run_still_frame_callbacks
12
+ def process(styles, options={})
13
+ super or
14
+ return
18
15
  end
19
16
 
20
17
  def process_style(*args)
21
18
  @operation = nil
19
+ @arguments = []
20
+ @still_frame_callbacks = []
22
21
  super
23
22
  set_default_operation
24
23
  run_ffmpeg
24
+ run_still_frame_callbacks
25
25
  end
26
26
 
27
27
  def use_threads(num_threads)
@@ -65,7 +65,7 @@ module Bulldog
65
65
  if (attribute = params[:assign_to])
66
66
  basename = "recorded_frame.#{params[:format]}"
67
67
  output_path = record.send(attribute).interpolate_path(:original, :basename => basename)
68
- @still_frame_callbacks[style] << lambda do
68
+ @still_frame_callbacks << lambda do
69
69
  file = SavedFile.new(output_path, :file_name => basename)
70
70
  record.update_attribute(attribute, file)
71
71
  end
@@ -75,7 +75,7 @@ module Bulldog
75
75
 
76
76
  operate '-y', output_path
77
77
  if block
78
- @still_frame_callbacks[style] << lambda{instance_exec(output_path, &block)}
78
+ @still_frame_callbacks << lambda{instance_exec(output_path, &block)}
79
79
  end
80
80
  end
81
81
 
@@ -88,7 +88,7 @@ module Bulldog
88
88
  end
89
89
 
90
90
  def operate(*args)
91
- @arguments[style].concat args.map(&:to_s)
91
+ @arguments.concat args.map(&:to_s)
92
92
  end
93
93
 
94
94
  def set_default_operation
@@ -154,15 +154,13 @@ module Bulldog
154
154
  def run_ffmpeg
155
155
  command = [self.class.ffmpeg_path]
156
156
  command << '-i' << input_file
157
- command.concat(@arguments[style])
157
+ command.concat(@arguments)
158
158
  Bulldog.run(*command) or
159
159
  record.errors.add name, "convert failed (status #$?)"
160
160
  end
161
161
 
162
162
  def run_still_frame_callbacks
163
- @still_frame_callbacks.each do |style, callbacks|
164
- callbacks.each{|c| c.call}
165
- end
163
+ @still_frame_callbacks.each(&:call)
166
164
  end
167
165
  end
168
166
  end
@@ -10,12 +10,12 @@ module Bulldog
10
10
 
11
11
  def initialize(*args)
12
12
  super
13
- @tree = ArgumentTree.new(styles)
14
13
  end
15
14
 
16
- def process
17
- return if styles.empty?
18
- super
15
+ def process(styles, options={})
16
+ @tree = ArgumentTree.new(styles)
17
+ super or
18
+ return
19
19
  run_convert
20
20
  end
21
21
 
@@ -6,7 +6,7 @@ module Bulldog
6
6
  @styles = StyleSet.new
7
7
  end
8
8
 
9
- def process(&block)
9
+ def process(*args, &block)
10
10
  @style = nil
11
11
  process_style(&block)
12
12
  end
@@ -51,7 +51,7 @@ describe Processor::Ffmpeg do
51
51
  configure(:video) do
52
52
  process(options.merge(:on => :event, :with => :ffmpeg), &block)
53
53
  end
54
- @thing.video.process(:event)
54
+ @thing.video.process(:event, options)
55
55
  end
56
56
 
57
57
  describe "#process" do
@@ -61,6 +61,20 @@ describe Processor::Ffmpeg do
61
61
  process_video
62
62
  end
63
63
 
64
+ it "should process the specified set of styles, if given, even those not in the configured style set" do
65
+ video_style :one
66
+ video_style :two
67
+ video_style :three
68
+ styles = []
69
+ configure :video do
70
+ process(:on => :event, :with => :image_magick, :styles => [:one, :two]) do
71
+ styles << style.name
72
+ end
73
+ end
74
+ @thing.video.process(:event, :styles => [:two, :three])
75
+ styles.should == [:two, :three]
76
+ end
77
+
64
78
  it "should log the command run" do
65
79
  video_style :output
66
80
  log_path = "#{temporary_directory}/log"
@@ -34,11 +34,11 @@ describe Processor::ImageMagick do
34
34
  end
35
35
  end
36
36
 
37
- def process(&block)
37
+ def process(*args, &block)
38
38
  configure do
39
39
  process(:on => :event, :with => :image_magick, &block)
40
40
  end
41
- @thing.attachment.process(:event)
41
+ @thing.attachment.process(:event, *args)
42
42
  end
43
43
 
44
44
  describe "#dimensions" do
@@ -78,6 +78,20 @@ describe Processor::ImageMagick do
78
78
  process
79
79
  end
80
80
 
81
+ it "should process the specified set of styles, if given, even those not in the configured style set" do
82
+ style :one
83
+ style :two
84
+ style :three
85
+ styles = []
86
+ configure do
87
+ process(:on => :event, :with => :image_magick, :styles => [:one, :two]) do
88
+ styles << style.name
89
+ end
90
+ end
91
+ @thing.attachment.process(:event, :styles => [:two, :three])
92
+ styles.should == [:two, :three]
93
+ end
94
+
81
95
  it "should add an error to the record if convert fails" do
82
96
  style :output
83
97
  Bulldog.stubs(:run).returns(nil)
@@ -72,8 +72,8 @@ describe Processor::OneShot do
72
72
  it "should not affect the other processes' styles" do
73
73
  style = Style.new(:style)
74
74
  styles = StyleSet[style]
75
- processor = Processor::OneShot.new(mock, styles, mock)
76
- processor.process{}
75
+ processor = Processor::OneShot.new(mock, mock)
76
+ processor.process(styles){}
77
77
  styles.should have(1).style
78
78
  end
79
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulldog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Ogata
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 -05:00
12
+ date: 2009-11-23 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency