hydra-file_characterization 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6204254cf414cf91d235b4945f6aca5fd7f91be
|
4
|
+
data.tar.gz: 66cf0f285dc7d271e6729efb31d168739dd7318b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372c0590a3108dfe0d11850e606caabfdd095a910b9254f5a7259e67cf96c0c943a8a965fc9fc07e1ccfa32a83c0a8fde50b08075dbc85f23c1798ded75ae453
|
7
|
+
data.tar.gz: 88ef7cfa899b8b0537f1550732936898d9e9e162f117e609c731ad135e5e177d0d67f00f811c3838fc92200229bdb8c3f43153d4683a5208ab96e71020b2011e
|
@@ -60,7 +60,7 @@ module Hydra
|
|
60
60
|
tool_names = Array(tool_names).flatten.compact
|
61
61
|
custom_paths = {}
|
62
62
|
yield(custom_paths) if block_given?
|
63
|
-
FileCharacterization::ToTempFile.open(
|
63
|
+
FileCharacterization::ToTempFile.open(filename, content) do |f|
|
64
64
|
tool_names.each do |tool_name|
|
65
65
|
tool_outputs << FileCharacterization.characterize_with(tool_name, f.path, custom_paths[tool_name])
|
66
66
|
end
|
@@ -5,40 +5,32 @@ module Hydra::FileCharacterization
|
|
5
5
|
class ToTempFile
|
6
6
|
include Open3
|
7
7
|
|
8
|
-
def self.open(
|
9
|
-
new(
|
8
|
+
def self.open(filename, data, &block)
|
9
|
+
new(filename).call(data, &block)
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_reader :
|
12
|
+
attr_reader :filename
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
self.data = data
|
14
|
+
def initialize(filename)
|
16
15
|
@filename = filename
|
17
16
|
end
|
18
17
|
|
19
|
-
def call
|
18
|
+
def call(data)
|
20
19
|
f = Tempfile.new([File.basename(filename),File.extname(filename)])
|
21
20
|
begin
|
22
|
-
|
23
|
-
|
21
|
+
if data.respond_to? :read
|
22
|
+
f.write(data.read)
|
23
|
+
else
|
24
|
+
f.write(data)
|
25
|
+
end
|
24
26
|
f.rewind
|
25
27
|
yield(f)
|
26
28
|
ensure
|
29
|
+
data.rewind if data.respond_to? :rewind
|
27
30
|
f.close
|
28
31
|
f.unlink
|
29
32
|
end
|
30
|
-
|
31
33
|
end
|
32
34
|
|
33
|
-
protected
|
34
|
-
|
35
|
-
def data=(value)
|
36
|
-
if value.respond_to?(:read)
|
37
|
-
@data = value.read
|
38
|
-
value.rewind if value.respond_to?(:rewind)
|
39
|
-
else
|
40
|
-
@data = value
|
41
|
-
end
|
42
|
-
end
|
43
35
|
end
|
44
|
-
end
|
36
|
+
end
|
@@ -11,7 +11,7 @@ module Hydra::FileCharacterization
|
|
11
11
|
describe '.open' do
|
12
12
|
subject { ToTempFile }
|
13
13
|
it 'creates a tempfile then unlinks it' do
|
14
|
-
subject.open(
|
14
|
+
subject.open(filename, content) do |temp_file|
|
15
15
|
@temp_file = temp_file
|
16
16
|
expect(File.exist?(@temp_file.path)).to eq true
|
17
17
|
expect(File.extname(@temp_file.path)).to include '.rb'
|
@@ -21,16 +21,29 @@ module Hydra::FileCharacterization
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe 'instance' do
|
24
|
-
subject { ToTempFile.new(
|
24
|
+
subject { ToTempFile.new(filename) }
|
25
25
|
it 'create a tempfile that exists' do
|
26
|
-
subject.call do |temp_file|
|
26
|
+
subject.call(content) do |temp_file|
|
27
|
+
temp_file.rewind
|
28
|
+
expect(temp_file.read).to eq(content)
|
27
29
|
@temp_file = temp_file
|
28
30
|
expect(File.exist?(@temp_file.path)).to eq true
|
29
31
|
expect(File.extname(@temp_file.path)).to include '.rb'
|
30
32
|
end
|
31
33
|
expect(@temp_file.path).to eq nil
|
32
34
|
end
|
35
|
+
|
36
|
+
context 'with file handle' do
|
37
|
+
let(:filename) { __FILE__ }
|
38
|
+
let(:content) { File.open(__FILE__, 'rb') }
|
39
|
+
it 'works' do
|
40
|
+
subject.call(content) do |temp_file|
|
41
|
+
temp_file.rewind
|
42
|
+
expect(temp_file.read).to eq File.read(__FILE__)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
33
46
|
end
|
34
47
|
|
35
48
|
end
|
36
|
-
end
|
49
|
+
end
|