Skip to content

Instantly share code, notes, and snippets.

@codatory
Created January 24, 2012 01:44
Show Gist options
  • Save codatory/1667259 to your computer and use it in GitHub Desktop.
Save codatory/1667259 to your computer and use it in GitHub Desktop.
class ExifData
require 'celluloid'
def initialize(file)
raise 'Expects Upload!' unless file.is_a?(Upload)
@upload = file
end
def process!
# this is fictitional
@exif_data ||= ActiveExif::new(@upload.read).process.to_hash
end
end
class MagickData
require 'celluloid'
def initialize(file)
raise 'Expects Upload!' unless file.is_a?(Upload)
@upload = file
end
def process!
# this is fictitional
@exif_data ||= ActiveMagick::new(@upload.read).process.to_hash
end
end
class Upload
def initialize(file)
@file = File.open(file)
end
def read
@image ||= @file.read
end
end
upload = Upload.new('/tmp/file.jpg')
# WILL NOT block
exif_data = ExifData.new(upload).future :process!
magick_data = MagickData.new(upload).future :process!
# WILL block
data = exif_data.value + magick_data.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment