content_type 2.1.4 → 2.2.0

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.
Files changed (4) hide show
  1. data/Rakefile +6 -8
  2. data/ext/extconf.rb +9 -2
  3. metadata +74 -14
  4. data/spec/content_type_spec.rb +0 -121
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
- require 'vendor/gems/environment'
2
-
3
1
  require 'rake'
4
- require 'spec'
5
- require 'spec/rake/spectask'
2
+ require 'jeweler'
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
6
5
 
7
6
  task :default => [:clean, :make, :spec]
8
7
 
@@ -13,16 +12,15 @@ task :make do
13
12
  end
14
13
  end
15
14
 
16
- Spec::Rake::SpecTask.new(:spec) do |t|
17
- t.spec_opts = %w(-fs -c)
18
- t.spec_files = FileList['spec/*_spec.rb']
15
+ RSpec::Core::RakeTask.new(:spec) do |t|
16
+ t.rspec_opts = %w(-fs -c)
17
+ t.pattern = FileList['spec/*_spec.rb']
19
18
  end
20
19
 
21
20
  task :clean do
22
21
  `rm -r ext/*.o ext/*.so ext/*.bundle ext/conftest.dSYM 2>/dev/null`
23
22
  end
24
23
 
25
- require 'jeweler'
26
24
  Jeweler::Tasks.new do |s|
27
25
  s.name = 'content_type'
28
26
  s.summary = 'libmagic bindings to quickly determine content type of files'
data/ext/extconf.rb CHANGED
@@ -4,8 +4,15 @@ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
4
4
  extension_name = 'content_type'
5
5
  dir_config(extension_name)
6
6
 
7
- find_header('magic.h', '/opt/local/include')
8
- find_library('magic', 'magic_open', '/opt/local/lib')
7
+ brew_magic = Dir['/usr/local/Cellar/libmagic/**/magic.h']
8
+ if brew_magic
9
+ brew_dir = File.dirname(File.dirname(brew_magic[0]))
10
+ find_header('magic.h', File.join(brew_dir, 'include'))
11
+ find_library('magic', 'magic_open', File.join(brew_dir, 'lib'))
12
+ else
13
+ find_header('magic.h', '/opt/local/include')
14
+ find_library('magic', 'magic_open', '/opt/local/lib')
15
+ end
9
16
 
10
17
  $CFLAGS += ' -Werror -Wall'
11
18
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_type
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 7
5
+ prerelease:
5
6
  segments:
6
7
  - 2
7
- - 1
8
- - 4
9
- version: 2.1.4
8
+ - 2
9
+ - 0
10
+ version: 2.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Turnbull
@@ -14,10 +15,66 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-14 00:00:00 +10:00
18
- default_executable:
19
- dependencies: []
20
-
18
+ date: 2011-05-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: rake
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: rspec
45
+ prerelease: false
46
+ type: :runtime
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: jeweler
59
+ prerelease: false
60
+ type: :runtime
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 27
69
+ segments:
70
+ - 0
71
+ - 1
72
+ - 0
73
+ version: 0.1.0
74
+ name: should_be_faster
75
+ prerelease: false
76
+ type: :runtime
77
+ requirement: *id004
21
78
  description: " Provides ContentType#content_type, File#content_type, File::content_type\n and String#content_type methods to determine mime type\n"
22
79
  email: dsturnbull@me.com
23
80
  executables: []
@@ -31,35 +88,38 @@ files:
31
88
  - ext/content_type.c
32
89
  - ext/extconf.rb
33
90
  - README
34
- has_rdoc: true
35
91
  homepage: http://github.com/dsturnbull/content_type
36
92
  licenses: []
37
93
 
38
94
  post_install_message:
39
- rdoc_options:
40
- - --charset=UTF-8
95
+ rdoc_options: []
96
+
41
97
  require_paths:
42
98
  - lib
43
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
44
101
  requirements:
45
102
  - - ">="
46
103
  - !ruby/object:Gem::Version
104
+ hash: 3
47
105
  segments:
48
106
  - 0
49
107
  version: "0"
50
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
51
110
  requirements:
52
111
  - - ">="
53
112
  - !ruby/object:Gem::Version
113
+ hash: 3
54
114
  segments:
55
115
  - 0
56
116
  version: "0"
57
117
  requirements: []
58
118
 
59
119
  rubyforge_project:
60
- rubygems_version: 1.3.6
120
+ rubygems_version: 1.7.2
61
121
  signing_key:
62
122
  specification_version: 3
63
123
  summary: libmagic bindings to quickly determine content type of files
64
- test_files:
65
- - spec/content_type_spec.rb
124
+ test_files: []
125
+
@@ -1,121 +0,0 @@
1
- require 'rubygems'
2
- require 'should_be_faster'
3
- require 'tempfile'
4
- require 'ext/content_type'
5
-
6
- describe ContentType do
7
- before do
8
- @img = 'spec/fixtures/grindewald.jpg'
9
- @pdf = 'spec/fixtures/pdftest.pdf'
10
- @lzm = 'spec/fixtures/compressed.jpg.lz'
11
- @doc = 'spec/fixtures/wordtest.doc'
12
- @dcx = 'spec/fixtures/wordtest.docx'
13
- @dot = 'spec/fixtures/.supercabanafuntimekgozzzzzzzzzzzzzzzzzzzz'
14
- @pdf_with_charset = 'spec/fixtures/bash.pdf'
15
- end
16
-
17
- context 'initialising' do
18
- it 'should take a file path' do
19
- path = @img
20
- ct = ContentType.new(path)
21
- ct.filepath.should == path
22
- end
23
-
24
- it 'should check that the file exists' do
25
- lambda {
26
- ct = ContentType.new('poopstain')
27
- }.should raise_error ArgumentError
28
- end
29
-
30
- it 'should memoize the content type' do
31
- ct = ContentType.new(@img)
32
- lambda {
33
- ct.content_type.should == 'image/jpeg'
34
- }.should change(ct, :processed).to(true)
35
- end
36
- end
37
-
38
- context 'file ext overrides' do
39
- it 'should detect docx files' do
40
- ct = ContentType.new(@dcx)
41
- ct.content_type.should ==
42
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
43
- end
44
-
45
- it 'should handle dot files' do
46
- ct = ContentType.new(@dot)
47
- ct.content_type.should == 'text/plain'
48
- end
49
- end
50
-
51
- context 'detecting mime type' do
52
- it 'should detect images' do
53
- ct = ContentType.new(@img)
54
- ct.content_type.should == 'image/jpeg'
55
- end
56
-
57
- it 'should detect pdfs' do
58
- ct = ContentType.new(@pdf)
59
- ct.content_type.should == 'application/pdf'
60
- end
61
-
62
- it 'should detect mime types with charsets by ignoring the charset' do
63
- ct = ContentType.new(@pdf_with_charset)
64
- ct.content_type.should == 'application/pdf'
65
- end
66
-
67
- it 'should detect lzma files' do
68
- ct = ContentType.new(@lzm)
69
- ct.content_type.should == 'application/x-lzip'
70
- end
71
-
72
- it 'should detect doc files' do
73
- ct = ContentType.new(@doc)
74
- ct.content_type.should == 'application/msword'
75
- end
76
- end
77
-
78
- context 'comparing with shelling out' do
79
- it 'should be much faster' do
80
- shell = lambda { `file -i #{@img}` }
81
- ext = lambda { ContentType.new(@img).content_type }
82
- ext.should be_at_least(5).times.faster_than(shell)
83
- end
84
-
85
- it 'should slower to reinstantiate' do
86
- @ct = ContentType.new(@img)
87
- memo = lambda { @ct.content_type }
88
- kgo = lambda { ContentType.new(@img).content_type }
89
- kgo.should be_at_least(5).times.slower_than(memo, :iterations => 1000)
90
- end
91
- end
92
-
93
- context 'when using the file class methods' do
94
- it 'should have File.content_type(path)' do
95
- File.content_type(@img).should == 'image/jpeg'
96
- end
97
-
98
- it 'should have File#content_type' do
99
- File.open(@img).content_type.should == 'image/jpeg'
100
- end
101
-
102
- it 'should make it into tempfile' do
103
- t = Tempfile.new('hi')
104
- t.content_type.should == 'application/x-empty'
105
- t << File.read(@img)
106
- t.content_type.should == 'image/jpeg'
107
- File.unlink(t.path)
108
- end
109
- end
110
-
111
- context 'on strings' do
112
- it 'should have String#content_type' do
113
- str = File.read(@img)
114
- str.content_type.should == 'image/jpeg'
115
- end
116
-
117
- it 'should work on empty strings' do
118
- ''.content_type.should == 'application/x-empty'
119
- end
120
- end
121
- end