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: f06158f27d8f23bf343080bfc2d180db0027fbf3
4
- data.tar.gz: ba88fb9630837746d4a039e1d9ce62ad98d1311e
3
+ metadata.gz: d6204254cf414cf91d235b4945f6aca5fd7f91be
4
+ data.tar.gz: 66cf0f285dc7d271e6729efb31d168739dd7318b
5
5
  SHA512:
6
- metadata.gz: c0753ac59e9409cb56fdbbcce950637f4f09ce976fcf25067c23d5f552b5fa9ae6d0565170e82aa8e085cd9ba29a7419a0e85dacab31d0525d3fb52c3b3e1141
7
- data.tar.gz: 0199b35addc4f239b3f3c5f938ad8bdd24a58d2bf92cff33ef65a49e6803afbb4aa49fffd7d59d1c8b656e02a423dd601987896722e2f5bb2a0a457dbb9098d1
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(content, filename) do |f|
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(*args, &block)
9
- new(*args).call(&block)
8
+ def self.open(filename, data, &block)
9
+ new(filename).call(data, &block)
10
10
  end
11
11
 
12
- attr_reader :data, :filename
12
+ attr_reader :filename
13
13
 
14
- def initialize(data, filename)
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
- f.binmode
23
- f.write(data)
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
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module FileCharacterization
3
- VERSION = "0.2.6"
3
+ VERSION = "0.2.7"
4
4
  end
5
5
  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(content, filename) do |temp_file|
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(content, filename) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-file_characterization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Treacy