hydra-file_characterization 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cff05141ecefe9beaec133587dda6bef344e10b7
4
+ data.tar.gz: 9479e89d684e59174fd1323e4ee1885495937a27
5
+ SHA512:
6
+ metadata.gz: 2275213d1646d9ca4c346bcb22bec3df42e37bced35e984d65615c87796d37a91389d4bfb3b5f90f1dd90ce18c134bf548be2925825ebe65b168d8112eb0210d
7
+ data.tar.gz: f732e2aed7c2a5d5b39a11d8caa698f2e73fd8944eab7772b4acfe6cc8988fbef6c110de6db37c178a3b1f820017b67aab7f066982d43290c9313f89b3af5ab8
data/README.md CHANGED
@@ -21,7 +21,7 @@ You can call a single characterizer…
21
21
  xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits)
22
22
  ```
23
23
 
24
- …for this particular call, you can specify custom fits path.
24
+ …for this particular call, you can specify custom fits path
25
25
 
26
26
  ```ruby
27
27
  xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits) do |config|
@@ -29,6 +29,14 @@ xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.
29
29
  end
30
30
  ```
31
31
 
32
+ …or even make the path callable
33
+
34
+ ```ruby
35
+ xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits) do |config|
36
+ config[:fits] = lambda {|filename| … }
37
+ end
38
+ ```
39
+
32
40
  You can also call multiple characterizers at the same time.
33
41
 
34
42
  ```ruby
@@ -18,6 +18,21 @@ module Hydra::FileCharacterization
18
18
  unless File.exists?(filename)
19
19
  raise Hydra::FileCharacterization::FileNotFoundError.new("File: #{filename} does not exist.")
20
20
  end
21
+
22
+ if tool_path.respond_to?(:call)
23
+ tool_path.call(filename)
24
+ else
25
+ internal_call
26
+ end
27
+ end
28
+
29
+ def tool_path
30
+ @tool_path || self.class.tool_path || (raise Hydra::FileCharacterization::UnspecifiedToolPathError.new(self.class))
31
+ end
32
+
33
+ protected
34
+
35
+ def internal_call
21
36
  stdin, stdout, stderr, wait_thr = popen3(command)
22
37
  begin
23
38
  out = stdout.read
@@ -32,12 +47,6 @@ module Hydra::FileCharacterization
32
47
  end
33
48
  end
34
49
 
35
- def tool_path
36
- @tool_path || self.class.tool_path || (raise Hydra::FileCharacterization::UnspecifiedToolPathError.new(self.class))
37
- end
38
-
39
- protected
40
-
41
50
  def command
42
51
  raise NotImplementedError, "Method #command should be overriden in child classes"
43
52
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module FileCharacterization
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'hydra/file_characterization/characterizer'
3
2
 
4
3
  module Hydra::FileCharacterization
5
4
  describe Characterizer do
@@ -14,25 +13,43 @@ module Hydra::FileCharacterization
14
13
  Hydra::FileCharacterization::Characterizer.tool_path = nil
15
14
  end
16
15
 
17
- context 'with custom instance tool_path' do
18
- let(:instance_tool_path) { '/arbitrary/path' }
19
- let(:class_tool_path) { '/a_different/path' }
16
+ context 'call' do
17
+ context 'with missing file' do
18
+ let(:filename) { '/dev/path/to/bogus/file' }
19
+ it 'should raise FileNotFoundError' do
20
+ expect { subject.call }.to raise_error(FileNotFoundError)
21
+ end
22
+ end
20
23
 
21
- its(:tool_path) { should eq instance_tool_path}
24
+ context 'with a callable tool path' do
25
+ let(:class_tool_path) { lambda { |filename| [filename, :output] }}
26
+ it 'should raise FileNotFoundError' do
27
+ expect(subject.call).to eq [filename, :output]
28
+ end
29
+ end
22
30
  end
23
31
 
24
- context 'with custom class tool_path' do
25
- let(:instance_tool_path) { nil }
26
- let(:class_tool_path) { '/a_different/path' }
32
+ context 'tool_path' do
33
+ context 'with custom instance tool_path' do
34
+ let(:instance_tool_path) { '/arbitrary/path' }
35
+ let(:class_tool_path) { '/a_different/path' }
27
36
 
28
- its(:tool_path) { should eq class_tool_path}
29
- end
37
+ its(:tool_path) { should eq instance_tool_path}
38
+ end
39
+
40
+ context 'with custom class tool_path' do
41
+ let(:instance_tool_path) { nil }
42
+ let(:class_tool_path) { '/a_different/path' }
43
+
44
+ its(:tool_path) { should eq class_tool_path}
45
+ end
30
46
 
31
- context 'without a specified tool_path' do
32
- it 'should raise Hydra::FileCharacterization::UnspecifiedToolPathError' do
33
- expect {
34
- subject.tool_path
35
- }.to raise_error(Hydra::FileCharacterization::UnspecifiedToolPathError)
47
+ context 'without a specified tool_path' do
48
+ it 'should raise Hydra::FileCharacterization::UnspecifiedToolPathError' do
49
+ expect {
50
+ subject.tool_path
51
+ }.to raise_error(Hydra::FileCharacterization::UnspecifiedToolPathError)
52
+ end
36
53
  end
37
54
  end
38
55
  end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,11 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
 
8
+ GEM_ROOT = File.expand_path("../../", __FILE__)
9
+ $:.unshift File.join(GEM_ROOT, "lib")
10
+
11
+ require 'hydra/file_characterization'
12
+
8
13
  module SpecSupport
9
14
  def fixture_file(filename)
10
15
  File.expand_path(File.join('../fixtures', filename), __FILE__)
metadata CHANGED
@@ -1,8 +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.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - James Treacy
@@ -17,65 +16,57 @@ dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: activesupport
19
18
  requirement: !ruby/object:Gem::Requirement
20
- none: false
21
19
  requirements:
22
- - - ! '>='
20
+ - - '>='
23
21
  - !ruby/object:Gem::Version
24
22
  version: 3.0.0
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
- - - ! '>='
27
+ - - '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: 3.0.0
33
30
  - !ruby/object:Gem::Dependency
34
31
  name: rspec
35
32
  requirement: !ruby/object:Gem::Requirement
36
- none: false
37
33
  requirements:
38
- - - ! '>='
34
+ - - '>='
39
35
  - !ruby/object:Gem::Version
40
36
  version: '0'
41
37
  type: :development
42
38
  prerelease: false
43
39
  version_requirements: !ruby/object:Gem::Requirement
44
- none: false
45
40
  requirements:
46
- - - ! '>='
41
+ - - '>='
47
42
  - !ruby/object:Gem::Version
48
43
  version: '0'
49
44
  - !ruby/object:Gem::Dependency
50
45
  name: guard
51
46
  requirement: !ruby/object:Gem::Requirement
52
- none: false
53
47
  requirements:
54
- - - ! '>='
48
+ - - '>='
55
49
  - !ruby/object:Gem::Version
56
50
  version: '0'
57
51
  type: :development
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
- none: false
61
54
  requirements:
62
- - - ! '>='
55
+ - - '>='
63
56
  - !ruby/object:Gem::Version
64
57
  version: '0'
65
58
  - !ruby/object:Gem::Dependency
66
59
  name: guard-rspec
67
60
  requirement: !ruby/object:Gem::Requirement
68
- none: false
69
61
  requirements:
70
- - - ! '>='
62
+ - - '>='
71
63
  - !ruby/object:Gem::Version
72
64
  version: '0'
73
65
  type: :development
74
66
  prerelease: false
75
67
  version_requirements: !ruby/object:Gem::Requirement
76
- none: false
77
68
  requirements:
78
- - - ! '>='
69
+ - - '>='
79
70
  - !ruby/object:Gem::Version
80
71
  version: '0'
81
72
  description: To provide a wrapper for file characterization
@@ -122,27 +113,26 @@ files:
122
113
  homepage: https://github.com/projecthydra/hydra-file_characterization
123
114
  licenses:
124
115
  - APACHE2
116
+ metadata: {}
125
117
  post_install_message:
126
118
  rdoc_options: []
127
119
  require_paths:
128
120
  - lib
129
121
  required_ruby_version: !ruby/object:Gem::Requirement
130
- none: false
131
122
  requirements:
132
- - - ! '>='
123
+ - - '>='
133
124
  - !ruby/object:Gem::Version
134
125
  version: '0'
135
126
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
127
  requirements:
138
- - - ! '>='
128
+ - - '>='
139
129
  - !ruby/object:Gem::Version
140
130
  version: '0'
141
131
  requirements: []
142
132
  rubyforge_project:
143
- rubygems_version: 1.8.25
133
+ rubygems_version: 2.0.7
144
134
  signing_key:
145
- specification_version: 3
135
+ specification_version: 4
146
136
  summary: To provide a wrapper for file characterization
147
137
  test_files:
148
138
  - spec/fixtures/archive.zip
@@ -158,4 +148,3 @@ test_files:
158
148
  - spec/lib/hydra/file_characterization/to_temp_file_spec.rb
159
149
  - spec/lib/hydra/file_characterization_spec.rb
160
150
  - spec/spec_helper.rb
161
- has_rdoc: