content_type 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
+ require 'vendor/gems/environment'
2
+
1
3
  require 'rake'
2
4
  require 'spec'
3
5
  require 'spec/rake/spectask'
4
6
 
5
- require 'vendor/gems/environment'
6
-
7
7
  task :default => [:clean, :make, :spec]
8
8
 
9
9
  task :make do
data/ext/content_type.c CHANGED
@@ -18,6 +18,7 @@ VALUE file_singleton_content_type(VALUE self, VALUE path);
18
18
  VALUE string_content_type(VALUE self);
19
19
 
20
20
  bool content_type_file_ext(VALUE self, char *ext);
21
+ void magic_fail(const char *error);
21
22
 
22
23
  // http://www.webdeveloper.com/forum/showthread.php?t=162526
23
24
  const char *content_type_ext_overrides[][2] = {
@@ -39,8 +40,6 @@ const char *content_type_ext_overrides[][2] = {
39
40
  { "xltm", "application/vnd.ms-excel.template.macroEnabled.12" },
40
41
  { "xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template" },
41
42
  };
42
-
43
- void magic_fail(const char *error);
44
43
 
45
44
  void
46
45
  Init_content_type()
@@ -65,6 +64,9 @@ Init_content_type()
65
64
  rb_define_method(rb_cString, "content_type", string_content_type, 0);
66
65
  }
67
66
 
67
+ // iv @content_type, @filepath and @processed are available in all variations
68
+ // because each implementation creates a ContentType obj through here
69
+ // (except String#content_type)
68
70
  VALUE
69
71
  content_type_initialize(VALUE self, VALUE path)
70
72
  {
@@ -76,13 +78,14 @@ content_type_initialize(VALUE self, VALUE path)
76
78
  rb_raise(rb_const_get(rb_cObject, rb_intern("ArgumentError")),
77
79
  "invalid file");
78
80
 
79
- rb_iv_set(self, "@content_type", rb_str_new("", 0));
80
- rb_iv_set(self, "@filepath", path);
81
- rb_iv_set(self, "@processed", Qfalse);
81
+ rb_iv_set(self, "@content_type", rb_str_new("", 0));
82
+ rb_iv_set(self, "@filepath", path);
83
+ rb_iv_set(self, "@processed", Qfalse);
82
84
 
83
85
  return self;
84
86
  }
85
87
 
88
+ // content_type_file_ext
86
89
  bool
87
90
  content_type_file_ext(VALUE self, char *ext)
88
91
  {
@@ -92,6 +95,8 @@ content_type_file_ext(VALUE self, char *ext)
92
95
 
93
96
  filepath = RSTRING_PTR(rb_iv_get(self, "@filepath"));
94
97
 
98
+ // go back until the first . from the end of the string
99
+ // then reverse the array
95
100
  j = 0;
96
101
  for (i = RSTRING_LEN(rb_iv_get(self, "@filepath")) - 1;
97
102
  i > 0 && j < MAX_EXT_LEN; i--) {
data/ext/extconf.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'mkmf'
2
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
2
3
 
3
4
  extension_name = 'content_type'
4
5
  dir_config(extension_name)
@@ -6,6 +7,6 @@ dir_config(extension_name)
6
7
  find_header('magic.h', '/opt/local/include')
7
8
  find_library('magic', 'magic_open', '/opt/local/lib')
8
9
 
9
- $CFLAGS += '-Werror -Wall'
10
+ $CFLAGS += ' -Werror -Wall'
10
11
 
11
12
  create_makefile(extension_name)
@@ -107,5 +107,9 @@ describe ContentType do
107
107
  str = File.read(@img)
108
108
  str.content_type.should == 'image/jpeg'
109
109
  end
110
+
111
+ it 'should work on empty strings' do
112
+ ''.content_type.should == 'application/x-empty'
113
+ end
110
114
  end
111
115
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 1
8
- - 1
9
- version: 2.1.1
8
+ - 2
9
+ version: 2.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Turnbull
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-08 00:00:00 +10:00
17
+ date: 2010-04-10 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies: []
20
20