ruby-filemagic 0.5.1 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc404160b6bdf763a0a5545a8dcc3494dca9c875
4
- data.tar.gz: 2d3998f17942cc9a98f88dfb86a9ceaf563139a4
3
+ metadata.gz: de14d26ab48eb9a2a818ed8e264e3e5ef2b0f85f
4
+ data.tar.gz: 96efd9c81179201c442d1886424bf712bb9eed44
5
5
  SHA512:
6
- metadata.gz: 16897fa6cf7f428b2873fe1e1386ddcfd743dfd466d4e46dbd1278ba4c817a7428516b55a3822ccd6cdfd09194f3bb3314e0c3ccb36945bd8ecfd99279fdf4c9
7
- data.tar.gz: 276914ae240cd3412b2d7361b061a8d010cd5f552ef1c08d26f55b9e2d097b8b5f265e8699bef19ddf920bb6c15bbc1d0b519f03f1429c09fb61427078ac3bb8
6
+ metadata.gz: e369f3dec254577adfa08f49f80de64e3156e592669a60eb53006621b9c2914a5ac74136f5073f2821f47e3ec6109c25793f00c26692856e3e8859dab1330982
7
+ data.tar.gz: d4db029e182841f8f62b927143b8f149ddbb0bc81f849e5169078acb3c3fdf3092f3a31da352d693e21497daa95d14db684488b6280f2d27b7c572bac9220113
data/ChangeLog CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  = Revision history for ruby-filemagic
4
4
 
5
+ == 0.5.2 [2014-04-24]
6
+
7
+ * Use MAGIC_VERSION if available.
8
+ * Made tests more robust.
9
+
5
10
  == 0.5.1 [2014-04-15]
6
11
 
7
12
  * New method FileMagic#io.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to filemagic version 0.5.1
5
+ This documentation refers to filemagic version 0.5.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -42,10 +42,10 @@ Travis
42
42
 
43
43
  == LINKS
44
44
 
45
- Homepage (defunct):: http://grub.ath.cx/filemagic/
46
- Documentation:: https://blackwinter.github.io/ruby-filemagic/
47
- Source code:: https://github.com/blackwinter/ruby-filemagic
48
- RubyGem:: https://rubygems.org/gems/ruby-filemagic
45
+ Homepage:: http://www.darwinsys.com/file/
46
+ Documentation:: https://blackwinter.github.io/ruby-filemagic/
47
+ Source code:: https://github.com/blackwinter/ruby-filemagic
48
+ RubyGem:: https://rubygems.org/gems/ruby-filemagic
49
49
 
50
50
 
51
51
  == AUTHORS
@@ -269,14 +269,19 @@ rb_magic_free(magic_t cookie) {
269
269
  magic_close(cookie);
270
270
  }
271
271
 
272
+ #define RB_MAGIC_SET_VERSION(m, p) sprintf(version, "%d.%02d", m, p);
273
+
272
274
  void
273
275
  Init_ruby_filemagic() {
274
276
  char version[8] = "0";
275
277
  cFileMagic = rb_define_class("FileMagic", rb_cObject);
276
278
 
277
- #ifdef FILE_VERSION_MAJOR
278
- sprintf(version, "%d.%02d", FILE_VERSION_MAJOR, patchlevel);
279
+ #if defined(FILE_VERSION_MAJOR)
280
+ RB_MAGIC_SET_VERSION(FILE_VERSION_MAJOR, patchlevel)
281
+ #elif defined(MAGIC_VERSION)
282
+ RB_MAGIC_SET_VERSION(MAGIC_VERSION / 100, MAGIC_VERSION % 100)
279
283
  #endif
284
+
280
285
  rb_define_const(cFileMagic, "MAGIC_VERSION", rb_str_new2(version));
281
286
 
282
287
  rb_define_singleton_method(cFileMagic, "new", rb_magic_new, -1);
@@ -4,7 +4,7 @@ class FileMagic
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 5
7
- TINY = 1
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
@@ -3,11 +3,25 @@ require 'filemagic'
3
3
 
4
4
  class TestFileMagic < Test::Unit::TestCase
5
5
 
6
+ magic_version = FileMagic::MAGIC_VERSION != '0' ? FileMagic::MAGIC_VERSION :
7
+ ENV['MAGIC_VERSION'] || begin
8
+ require 'nuggets/file/which'
9
+ %x{dpkg-query -f '${Version}' -W libmagic-dev} if File.which('dpkg-query')
10
+ rescue LoadError
11
+ end
12
+
13
+ MAGIC_VERSION = magic_version.to_f
14
+
6
15
  def test_file
7
16
  fm = FileMagic.new(FileMagic::MAGIC_NONE)
8
17
 
18
+ python_script = match_version(
19
+ 0 => 'a python script, ASCII text executable',
20
+ 5.11 => 'Python script, ASCII text executable'
21
+ )
22
+
9
23
  res = fm.file(path_to('pyfile'))
10
- assert_equal('Python script, ASCII text executable', res)
24
+ assert_equal(python_script, res)
11
25
 
12
26
  if File.symlink?(path_to('pylink'))
13
27
  res = fm.file(path_to('pylink'))
@@ -18,7 +32,7 @@ class TestFileMagic < Test::Unit::TestCase
18
32
  fm = FileMagic.new(FileMagic::MAGIC_SYMLINK)
19
33
 
20
34
  res = fm.file(path_to('pylink'))
21
- assert_equal('Python script, ASCII text executable', res)
35
+ assert_equal(python_script, res)
22
36
 
23
37
  fm.close
24
38
  fm = FileMagic.new(FileMagic::MAGIC_SYMLINK | FileMagic::MAGIC_MIME)
@@ -30,7 +44,7 @@ class TestFileMagic < Test::Unit::TestCase
30
44
  fm = FileMagic.new(FileMagic::MAGIC_COMPRESS)
31
45
 
32
46
  res = fm.file(path_to('pyfile-compressed.gz'))
33
- assert_match(/^Python script, ASCII text executable \(gzip compressed data, was "pyfile-compressed", from Unix/, res)
47
+ assert_match(/^#{python_script} \(gzip compressed data, was "pyfile-compressed", from Unix/, res)
34
48
 
35
49
  fm.close
36
50
  end
@@ -64,7 +78,10 @@ class TestFileMagic < Test::Unit::TestCase
64
78
  block_fm = fm
65
79
  fm.file(path_to('pyfile'))
66
80
  }
67
- assert_equal('Python script, ASCII text executable', res)
81
+ assert_equal(match_version(
82
+ 0 => 'a python script, ASCII text executable',
83
+ 5.11 => 'Python script, ASCII text executable'
84
+ ), res)
68
85
  assert block_fm.closed?
69
86
  end
70
87
 
@@ -97,7 +114,10 @@ class TestFileMagic < Test::Unit::TestCase
97
114
  def test_mahoro_file
98
115
  fm = FileMagic.new
99
116
  fm.flags = FileMagic::MAGIC_NONE
100
- assert_equal('C source, ASCII text', fm.file(path_to('mahoro.c')))
117
+ assert_equal(match_version(
118
+ 0 => 'ASCII C program text',
119
+ 5.11 => 'C source, ASCII text'
120
+ ), fm.file(path_to('mahoro.c')))
101
121
  end
102
122
 
103
123
  def test_mahoro_mime_file
@@ -109,7 +129,10 @@ class TestFileMagic < Test::Unit::TestCase
109
129
  def test_mahoro_buffer
110
130
  fm = FileMagic.new
111
131
  fm.flags = FileMagic::MAGIC_NONE
112
- assert_equal('C source, ASCII text', fm.buffer(File.read(path_to('mahoro.c'))))
132
+ assert_equal(match_version(
133
+ 0 => 'ASCII C program text',
134
+ 5.11 => 'C source, ASCII text'
135
+ ), fm.buffer(File.read(path_to('mahoro.c'))))
113
136
  end
114
137
 
115
138
  def test_mahoro_mime_buffer
@@ -134,7 +157,10 @@ class TestFileMagic < Test::Unit::TestCase
134
157
  fm.simplified = true
135
158
  assert fm.simplified?
136
159
  assert_equal('text/plain', fm.file(path_to('perl')))
137
- assert_equal('application/msword', fm.file(path_to('excel-example.xls')))
160
+ assert_equal(match_version(
161
+ 0 => 'application/vnd.ms-office',
162
+ 5.11 => 'application/msword'
163
+ ), fm.file(path_to('excel-example.xls')))
138
164
  end
139
165
 
140
166
  # utility methods:
@@ -150,4 +176,8 @@ class TestFileMagic < Test::Unit::TestCase
150
176
  yield
151
177
  end
152
178
 
179
+ def match_version(versions)
180
+ versions.sort_by { |k,| -k }.find { |k,| k <= MAGIC_VERSION }.last
181
+ end
182
+
153
183
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-filemagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Whitton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-15 00:00:00.000000000 Z
12
+ date: 2014-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hen
@@ -92,14 +92,14 @@ licenses:
92
92
  metadata: {}
93
93
  post_install_message: |2+
94
94
 
95
- ruby-filemagic-0.5.1 [2014-04-15]:
95
+ ruby-filemagic-0.5.2 [2014-04-24]:
96
96
 
97
- * New method FileMagic#io.
98
- * Housekeeping.
97
+ * Use MAGIC_VERSION if available.
98
+ * Made tests more robust.
99
99
 
100
100
  rdoc_options:
101
101
  - "--title"
102
- - ruby-filemagic Application documentation (v0.5.1)
102
+ - ruby-filemagic Application documentation (v0.5.2)
103
103
  - "--charset"
104
104
  - UTF-8
105
105
  - "--line-numbers"
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.2.2.x
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Ruby bindings to the magic(4) library