-
-
Save sgrif/5920ca3d46a76b9286a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class S3FileCopier < Struct.new(:model_file, :filepath, :bucket_name, :additional_transformations) | |
def initialize(model_file, filepath, bucket_name, additional_transformations = []) | |
super | |
end | |
def copy | |
expected_file.write(transformed_file, content_encoding: :deflate) | |
end | |
handle_asynchronously :copy | |
private | |
def expected_file | |
bucket.objects[model_file.path.gsub(/^\//, '')] | |
end | |
def transformed_file | |
additional_transformations.reduce(original_file.read) do |file, transformer| | |
transformer.apply(file) | |
end | |
end | |
def original_file | |
bucket.objects[original_file_path] | |
end | |
def bucket | |
AWS.s3.buckets[bucket_name] | |
end | |
def original_file_path | |
CGI.unescape(stripped_file_name) | |
end | |
def stripped_file_name | |
filepath.gsub(/^\/#{bucket_name}\//, '') | |
end | |
end | |
module NullFileTransformer | |
def self.apply(data) | |
data | |
end | |
end | |
class ZlibFileTransformer | |
def initialize(level) | |
# Yes, this really does vary, we have a case where we can't use | |
# BEST_COMPRESSION | |
@level = level | |
end | |
def apply(data) | |
Zlib.deflate(data, level) | |
end | |
end | |
class BinaryFileConverter | |
def initialize(json_format_verson = 3) | |
@json_format_verson = json_format_version | |
end | |
def apply(json_string) | |
# Lots of intense binary conversion! | |
end | |
end | |
class ImageCompressor | |
def apply(image_data) | |
# Shells out to ImageMagick | |
end | |
end | |
class CodeMinifier | |
def initialize(whitelisted_method_names = [], include_block_arguments = true) | |
end | |
def apply(ruby_code) | |
# You get the picture | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment