Class: PyramidScheme::IndexProvider::S3
- Inherits:
-
Base
- Object
- Base
- PyramidScheme::IndexProvider::S3
show all
- Defined in:
- lib/pyramid_scheme/index_provider/s3.rb
Instance Attribute Summary
Attributes inherited from Base
#configuration, #copy_attempts
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#index_in_progress?, maximum_copy_attempts, #retrieve_index
Constructor Details
#initialize(options = {}) ⇒ S3
Returns a new instance of S3.
25
26
27
28
|
# File 'lib/pyramid_scheme/index_provider/s3.rb', line 25
def initialize(options = {})
super
self.class.establish_connection!
end
|
Class Method Details
.establish_connection! ⇒ Object
16
17
18
19
20
21
|
# File 'lib/pyramid_scheme/index_provider/s3.rb', line 16
def establish_connection!
@connection ||= AWS::S3::Base.establish_connection!(
:access_key_id => PyramidScheme.configuration[:access_key],
:secret_access_key => PyramidScheme.configuration[:secret_access_key]
)
end
|
.required_options ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/pyramid_scheme/index_provider/s3.rb', line 5
def required_options
[
:access_key,
:secret_access_key,
:bucket,
:prefix,
:server_source_path,
:client_destination_path
]
end
|
Instance Method Details
#lock ⇒ Object
50
51
52
|
# File 'lib/pyramid_scheme/index_provider/s3.rb', line 50
def lock
@lock ||= PyramidScheme::Lock::S3.new
end
|
#process_index ⇒ Object
30
31
32
|
# File 'lib/pyramid_scheme/index_provider/s3.rb', line 30
def process_index
server_copy
end
|
#provide_client_with_index ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/pyramid_scheme/index_provider/s3.rb', line 34
def provide_client_with_index
AWS::S3::Bucket.objects(@configuration[:bucket],
:prefix => "#{@configuration[:prefix]}/").each do |obj|
unless obj.key =~ /\.new\./
new_filename = File.basename(obj.key.gsub("#{@configuration[:prefix]}/", '').gsub(/\./, ".new."))
destined_path = File.join(@configuration[:client_destination_path], new_filename)
File.open(destined_path, 'w') do |file|
AWS::S3::S3Object.stream(obj.key, @configuration[:bucket]) do |chunk|
file.write chunk
end
end
end
end
end
|