content_type 2.1.1 → 2.1.2
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.
- data/Rakefile +2 -2
- data/ext/content_type.c +10 -5
- data/ext/extconf.rb +2 -1
- data/spec/content_type_spec.rb +4 -0
- metadata +3 -3
data/Rakefile
CHANGED
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",
|
80
|
-
rb_iv_set(self, "@filepath",
|
81
|
-
rb_iv_set(self, "@processed",
|
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)
|
data/spec/content_type_spec.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 2.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-
|
17
|
+
date: 2010-04-10 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|