dragonfly 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dragonfly might be problematic. Click here for more details.

data/Rakefile CHANGED
@@ -31,7 +31,7 @@ YARD::Rake::YardocTask.new do |t|
31
31
  t.options = %w(-e yard/setup.rb)
32
32
  end
33
33
  YARD::Rake::YardocTask.new 'yard:changed' do |t|
34
- t.files = `git stat | grep '.rb' | grep modified | grep -v yard | cut -d' ' -f4`.split
34
+ t.files = `git status | grep '.rb' | grep modified | grep -v yard | cut -d' ' -f4`.split
35
35
  t.options = %w(-e yard/setup.rb)
36
36
  end
37
37
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/dragonfly.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dragonfly}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Evans"]
12
- s.date = %q{2010-01-10}
12
+ s.date = %q{2010-01-24}
13
13
  s.email = %q{mark@new-bamboo.co.uk}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
  "lib/dragonfly/active_record_extensions/class_methods.rb",
52
52
  "lib/dragonfly/active_record_extensions/instance_methods.rb",
53
53
  "lib/dragonfly/active_record_extensions/validations.rb",
54
+ "lib/dragonfly/analyser_list.rb",
54
55
  "lib/dragonfly/analysis/base.rb",
55
56
  "lib/dragonfly/analysis/file_command_analyser.rb",
56
57
  "lib/dragonfly/analysis/r_magick_analyser.rb",
@@ -65,6 +66,7 @@ Gem::Specification.new do |s|
65
66
  "lib/dragonfly/data_storage/transparent_data_store.rb",
66
67
  "lib/dragonfly/delegatable.rb",
67
68
  "lib/dragonfly/delegator.rb",
69
+ "lib/dragonfly/encoder_list.rb",
68
70
  "lib/dragonfly/encoding/base.rb",
69
71
  "lib/dragonfly/encoding/r_magick_encoder.rb",
70
72
  "lib/dragonfly/encoding/transparent_encoder.rb",
@@ -73,6 +75,7 @@ Gem::Specification.new do |s|
73
75
  "lib/dragonfly/parameters.rb",
74
76
  "lib/dragonfly/processing/base.rb",
75
77
  "lib/dragonfly/processing/r_magick_processor.rb",
78
+ "lib/dragonfly/processor_list.rb",
76
79
  "lib/dragonfly/r_magick_configuration.rb",
77
80
  "lib/dragonfly/rails/images.rb",
78
81
  "lib/dragonfly/temp_object.rb",
@@ -89,6 +92,8 @@ Gem::Specification.new do |s|
89
92
  "spec/dragonfly/active_record_extensions/model_spec.rb",
90
93
  "spec/dragonfly/active_record_extensions/models.rb",
91
94
  "spec/dragonfly/active_record_extensions/spec_helper.rb",
95
+ "spec/dragonfly/analyser_list_spec.rb",
96
+ "spec/dragonfly/analysis/file_command_analyser_spec.rb",
92
97
  "spec/dragonfly/analysis/r_magick_analyser_spec.rb",
93
98
  "spec/dragonfly/app_spec.rb",
94
99
  "spec/dragonfly/configurable_spec.rb",
@@ -128,6 +133,8 @@ Gem::Specification.new do |s|
128
133
  "spec/dragonfly/active_record_extensions/model_spec.rb",
129
134
  "spec/dragonfly/active_record_extensions/models.rb",
130
135
  "spec/dragonfly/active_record_extensions/spec_helper.rb",
136
+ "spec/dragonfly/analyser_list_spec.rb",
137
+ "spec/dragonfly/analysis/file_command_analyser_spec.rb",
131
138
  "spec/dragonfly/analysis/r_magick_analyser_spec.rb",
132
139
  "spec/dragonfly/app_spec.rb",
133
140
  "spec/dragonfly/configurable_spec.rb",
@@ -0,0 +1,15 @@
1
+ module Dragonfly
2
+ class AnalyserList
3
+ include Delegator
4
+
5
+ def mime_type(temp_object)
6
+ registered_objects.reverse.each do |analyser|
7
+ catch :unable_to_handle do
8
+ return analyser.mime_type(temp_object) if analyser.respond_to?(:mime_type)
9
+ end
10
+ end
11
+ nil
12
+ end
13
+
14
+ end
15
+ end
@@ -5,11 +5,19 @@ module Dragonfly
5
5
 
6
6
  include Configurable
7
7
 
8
- configurable_attr :file_command do `which file`.chomp end
8
+ configurable_attr :file_command, "file"
9
+ configurable_attr :use_filesystem, false
9
10
 
10
11
  def mime_type(temp_object)
11
- output = `#{file_command} -b --mime #{temp_object.path}`
12
- output.split(';').first
12
+ if use_filesystem
13
+ `#{file_command} -b --mime '#{temp_object.path}'`
14
+ else
15
+ IO.popen("#{file_command} -b --mime -", 'r+') do |io|
16
+ io.write temp_object.data
17
+ io.close_write
18
+ io.read
19
+ end
20
+ end.split(';').first
13
21
  end
14
22
 
15
23
  end
data/lib/dragonfly/app.rb CHANGED
@@ -70,7 +70,7 @@ module Dragonfly
70
70
  end
71
71
 
72
72
  def initialize
73
- @analysers, @processors, @encoders = Delegator.new, Delegator.new, Delegator.new
73
+ @analysers, @processors, @encoders = AnalyserList.new, ProcessorList.new, EncoderList.new
74
74
  @parameters_class = Class.new(Parameters)
75
75
  @url_handler = UrlHandler.new(@parameters_class)
76
76
  initialize_temp_object_class
@@ -1,5 +1,5 @@
1
1
  module Dragonfly
2
- class Delegator
2
+ module Delegator
3
3
 
4
4
  # This gets raised if no delegated objects are able to handle
5
5
  # the method call, even though they respond to that method.
@@ -0,0 +1,5 @@
1
+ module Dragonfly
2
+ class EncoderList
3
+ include Delegator
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Dragonfly
2
+ class ProcessorList
3
+ include Delegator
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Dragonfly::AnalyserList do
4
+
5
+ class EggHeads
6
+ include Dragonfly::Delegatable
7
+ def mime_type(temp_object)
8
+ "text/eggnog"
9
+ end
10
+ end
11
+
12
+ class Dingbats
13
+ include Dragonfly::Delegatable
14
+ def mime_type(temp_object)
15
+ throw :unable_to_handle
16
+ end
17
+ end
18
+
19
+ before(:each) do
20
+ @analysers = Dragonfly::AnalyserList.new
21
+ end
22
+
23
+ describe "mime_type" do
24
+ before(:each) do
25
+ @temp_object = Dragonfly::TempObject.new 'asdfa'
26
+ end
27
+ it "should return the mime type as per usual if the registered analysers implement it" do
28
+ @analysers.register(EggHeads)
29
+ @analysers.mime_type(@temp_object).should == 'text/eggnog'
30
+ end
31
+ it "should return the mime_type as nil if the registered analysers don't implement it" do
32
+ @analysers.mime_type(@temp_object).should be_nil
33
+ end
34
+ it "should return the mime_type as nil if the registered analysers throw :unable_to_handle" do
35
+ @analysers.register(Dingbats)
36
+ @analysers.mime_type(@temp_object).should be_nil
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ png_path = File.dirname(__FILE__) + '/../../../samples/egg.png'
4
+
5
+ describe Dragonfly::Analysis::FileCommandAnalyser do
6
+
7
+ before(:each) do
8
+ @analyser = Dragonfly::Analysis::FileCommandAnalyser.new
9
+ end
10
+
11
+ describe "mime_type" do
12
+
13
+ describe "when using the filesystem" do
14
+ before(:each) do
15
+ @analyser.use_filesystem = true
16
+ @temp_object = Dragonfly::TempObject.new(File.new(png_path))
17
+ end
18
+ it "should give the mime-type" do
19
+ @analyser.mime_type(@temp_object).should == 'image/png'
20
+ end
21
+ it "should not have initialized the data string" do
22
+ @analyser.mime_type(@temp_object)
23
+ @temp_object.instance_eval{@data}.should be_nil
24
+ end
25
+ end
26
+
27
+ describe "when not using the filesystem" do
28
+ before(:each) do
29
+ @analyser.use_filesystem = false
30
+ @temp_object = Dragonfly::TempObject.new(File.read(png_path))
31
+ end
32
+ it "should give the mime-type" do
33
+ @analyser.mime_type(@temp_object).should == 'image/png'
34
+ end
35
+ it "should not have initialized the file" do
36
+ @analyser.mime_type(@temp_object)
37
+ @temp_object.instance_eval{@tempfile}.should be_nil
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -44,7 +44,8 @@ end
44
44
  describe Dragonfly::Delegator do
45
45
 
46
46
  before(:each) do
47
- @delegator = Dragonfly::Delegator.new
47
+ @delegator = Object.new
48
+ @delegator.extend Dragonfly::Delegator
48
49
  end
49
50
 
50
51
  describe "when no items have been registered" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-10 00:00:00 +00:00
12
+ date: 2010-01-24 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,7 @@ files:
67
67
  - lib/dragonfly/active_record_extensions/class_methods.rb
68
68
  - lib/dragonfly/active_record_extensions/instance_methods.rb
69
69
  - lib/dragonfly/active_record_extensions/validations.rb
70
+ - lib/dragonfly/analyser_list.rb
70
71
  - lib/dragonfly/analysis/base.rb
71
72
  - lib/dragonfly/analysis/file_command_analyser.rb
72
73
  - lib/dragonfly/analysis/r_magick_analyser.rb
@@ -81,6 +82,7 @@ files:
81
82
  - lib/dragonfly/data_storage/transparent_data_store.rb
82
83
  - lib/dragonfly/delegatable.rb
83
84
  - lib/dragonfly/delegator.rb
85
+ - lib/dragonfly/encoder_list.rb
84
86
  - lib/dragonfly/encoding/base.rb
85
87
  - lib/dragonfly/encoding/r_magick_encoder.rb
86
88
  - lib/dragonfly/encoding/transparent_encoder.rb
@@ -89,6 +91,7 @@ files:
89
91
  - lib/dragonfly/parameters.rb
90
92
  - lib/dragonfly/processing/base.rb
91
93
  - lib/dragonfly/processing/r_magick_processor.rb
94
+ - lib/dragonfly/processor_list.rb
92
95
  - lib/dragonfly/r_magick_configuration.rb
93
96
  - lib/dragonfly/rails/images.rb
94
97
  - lib/dragonfly/temp_object.rb
@@ -105,6 +108,8 @@ files:
105
108
  - spec/dragonfly/active_record_extensions/model_spec.rb
106
109
  - spec/dragonfly/active_record_extensions/models.rb
107
110
  - spec/dragonfly/active_record_extensions/spec_helper.rb
111
+ - spec/dragonfly/analyser_list_spec.rb
112
+ - spec/dragonfly/analysis/file_command_analyser_spec.rb
108
113
  - spec/dragonfly/analysis/r_magick_analyser_spec.rb
109
114
  - spec/dragonfly/app_spec.rb
110
115
  - spec/dragonfly/configurable_spec.rb
@@ -166,6 +171,8 @@ test_files:
166
171
  - spec/dragonfly/active_record_extensions/model_spec.rb
167
172
  - spec/dragonfly/active_record_extensions/models.rb
168
173
  - spec/dragonfly/active_record_extensions/spec_helper.rb
174
+ - spec/dragonfly/analyser_list_spec.rb
175
+ - spec/dragonfly/analysis/file_command_analyser_spec.rb
169
176
  - spec/dragonfly/analysis/r_magick_analyser_spec.rb
170
177
  - spec/dragonfly/app_spec.rb
171
178
  - spec/dragonfly/configurable_spec.rb