remote_files 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remote_files.rb +10 -0
- data/lib/remote_files/configuration.rb +9 -0
- data/lib/remote_files/file.rb +9 -0
- data/lib/remote_files/version.rb +1 -1
- data/test/configuration_test.rb +26 -0
- data/test/file_test.rb +22 -0
- metadata +4 -4
data/lib/remote_files.rb
CHANGED
@@ -24,6 +24,16 @@ module RemoteFiles
|
|
24
24
|
CONFIGURATIONS[name.to_sym].from_hash(hash)
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.logger=(logger)
|
28
|
+
@logger = logger
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.logger
|
32
|
+
return @logger if defined?(@logger)
|
33
|
+
|
34
|
+
@logger ||= defined?(Rails) ? Rails.logger : nil
|
35
|
+
end
|
36
|
+
|
27
37
|
def self.add_store(store_identifier, options = {}, &block)
|
28
38
|
default_configuration.add_store(store_identifier, options, &block)
|
29
39
|
end
|
@@ -11,6 +11,14 @@ module RemoteFiles
|
|
11
11
|
from_hash(config)
|
12
12
|
end
|
13
13
|
|
14
|
+
def logger=(logger)
|
15
|
+
@logger = logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
@logger ||= RemoteFiles.logger
|
20
|
+
end
|
21
|
+
|
14
22
|
def clear
|
15
23
|
@stores.clear
|
16
24
|
@stores_map.clear
|
@@ -85,6 +93,7 @@ module RemoteFiles
|
|
85
93
|
file.stored_in << store.identifier
|
86
94
|
break
|
87
95
|
rescue ::RemoteFiles::Error => e
|
96
|
+
file.logger.info(e) if file.logger
|
88
97
|
exception = e
|
89
98
|
end
|
90
99
|
end
|
data/lib/remote_files/file.rb
CHANGED
@@ -13,9 +13,18 @@ module RemoteFiles
|
|
13
13
|
@content = options.delete(:content)
|
14
14
|
@content_type = options[:content_type]
|
15
15
|
@configuration = RemoteFiles::CONFIGURATIONS[(options[:configuration] || :default).to_sym]
|
16
|
+
@logger = options[:logger]
|
16
17
|
@options = options
|
17
18
|
end
|
18
19
|
|
20
|
+
def logger=(logger)
|
21
|
+
@logger = logger
|
22
|
+
end
|
23
|
+
|
24
|
+
def logger
|
25
|
+
@logger ||= configuration ? configuration.logger : RemoteFiles.logger
|
26
|
+
end
|
27
|
+
|
19
28
|
def self.from_url(url)
|
20
29
|
RemoteFiles.default_configuration.file_from_url(url)
|
21
30
|
end
|
data/lib/remote_files/version.rb
CHANGED
data/test/configuration_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require_relative 'test_helper'
|
2
3
|
require 'remote_files/mock_store'
|
3
4
|
|
@@ -9,6 +10,25 @@ describe RemoteFiles::Configuration do
|
|
9
10
|
@mock_store2 = @configuration.add_store(:mock2, :class => RemoteFiles::MockStore)
|
10
11
|
end
|
11
12
|
|
13
|
+
describe '#logger' do
|
14
|
+
it 'defaults to RemoteFiles.logger' do
|
15
|
+
logger = Logger.new($stdout)
|
16
|
+
RemoteFiles.logger = logger
|
17
|
+
configuration_logger = @configuration.logger
|
18
|
+
RemoteFiles.logger = nil
|
19
|
+
|
20
|
+
configuration_logger.must_equal logger
|
21
|
+
|
22
|
+
new_logger = Logger.new($stdout)
|
23
|
+
|
24
|
+
@configuration.logger = new_logger
|
25
|
+
@configuration.logger.must_equal new_logger
|
26
|
+
|
27
|
+
@configuration.logger = nil
|
28
|
+
@configuration.logger.must_be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
12
32
|
describe '::add_store' do
|
13
33
|
describe 'when adding a non-primary store' do
|
14
34
|
before { @non_primary_store = @configuration.add_store(:primary) }
|
@@ -64,6 +84,8 @@ describe RemoteFiles::Configuration do
|
|
64
84
|
|
65
85
|
describe 'when the first store fails' do
|
66
86
|
before do
|
87
|
+
@log = StringIO.new
|
88
|
+
@file.logger = Logger.new(@log)
|
67
89
|
@mock_store1.expects(:store!).with(@file).raises(RemoteFiles::Error)
|
68
90
|
@configuration.store_once!(@file)
|
69
91
|
end
|
@@ -72,6 +94,10 @@ describe RemoteFiles::Configuration do
|
|
72
94
|
@mock_store1.data['file'].must_be_nil
|
73
95
|
@mock_store2.data['file'].must_equal(:content => 'content', :content_type => 'text/plain')
|
74
96
|
end
|
97
|
+
|
98
|
+
it 'logs that the first store failed' do
|
99
|
+
@log.string.must_match /RemoteFiles::Error/
|
100
|
+
end
|
75
101
|
end
|
76
102
|
|
77
103
|
describe 'when alls stores fail' do
|
data/test/file_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require_relative 'test_helper'
|
2
3
|
|
3
4
|
describe RemoteFiles::File do
|
@@ -8,6 +9,27 @@ describe RemoteFiles::File do
|
|
8
9
|
@file = RemoteFiles::File.new('identifier')
|
9
10
|
end
|
10
11
|
|
12
|
+
describe '#logger' do
|
13
|
+
it 'defaults to the configuration logger' do
|
14
|
+
configuration_logger = Logger.new($stdout)
|
15
|
+
configuration = RemoteFiles.configure(:test)
|
16
|
+
configuration.logger = configuration_logger
|
17
|
+
|
18
|
+
file = RemoteFiles::File.new('identifier', :configuration => :test)
|
19
|
+
file.logger.must_equal configuration_logger
|
20
|
+
|
21
|
+
new_logger = Logger.new($stdout)
|
22
|
+
file.logger = new_logger
|
23
|
+
file.logger.must_equal new_logger
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'is settable at initialization' do
|
27
|
+
logger = Logger.new($stdout)
|
28
|
+
file = RemoteFiles::File.new('identifier', :logger => logger)
|
29
|
+
file.logger.must_equal logger
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
11
33
|
describe '#stored?' do
|
12
34
|
it 'should return true if the file is stored anywhere' do
|
13
35
|
@file.stored_in << :s3
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash:
|
151
|
+
hash: 424450237323346317
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
none: false
|
154
154
|
requirements:
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
segments:
|
159
159
|
- 0
|
160
|
-
hash:
|
160
|
+
hash: 424450237323346317
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
163
|
rubygems_version: 1.8.24
|