class Capybara::Screenshot::S3Saver
Constants
- DEFAULT_REGION
Attributes
bucket_name[R]
s3_client[R]
saver[R]
Public Class Methods
new(saver, s3_client, bucket_name)
click to toggle source
# File lib/capybara-screenshot/s3_saver.rb, line 8 def initialize(saver, s3_client, bucket_name) @saver = saver @s3_client = s3_client @bucket_name = bucket_name end
new_with_configuration(saver, configuration)
click to toggle source
# File lib/capybara-screenshot/s3_saver.rb, line 14 def self.new_with_configuration(saver, configuration) default_s3_client_credentials = { region: DEFAULT_REGION } s3_client_credentials = default_s3_client_credentials.merge( configuration.fetch(:s3_client_credentials) ) s3_client = Aws::S3::Client.new(s3_client_credentials) bucket_name = configuration.fetch(:bucket_name) new(saver, s3_client, bucket_name) rescue KeyError raise "Invalid S3 Configuration #{configuration}. Please refer to the documentation for the necessary configurations." end
Public Instance Methods
method_missing(method, *args)
click to toggle source
# File lib/capybara-screenshot/s3_saver.rb, line 44 def method_missing(method, *args) # Need to use @saver instead of S3Saver#saver attr_reader method because # using the method goes into infinite loop. Maybe attr_reader implements # its methods via method_missing? @saver.send(method, *args) end
save_and_upload_screenshot()
click to toggle source
# File lib/capybara-screenshot/s3_saver.rb, line 31 def save_and_upload_screenshot save_and do |local_file_path| File.open(local_file_path) do |file| s3_client.put_object( bucket: bucket_name, key: File.basename(local_file_path), body: file ) end end end
Also aliased as: save
Private Instance Methods
save_and() { |html_path| ... }
click to toggle source
# File lib/capybara-screenshot/s3_saver.rb, line 56 def save_and saver.save yield(saver.html_path) if block_given? && saver.html_saved? yield(saver.screenshot_path) if block_given? && saver.screenshot_saved? end