I’m trying to figure out the best way to add some functionality to
active record. I have a table of files, and need to write a set of core
functions that do different things depending on the type of file eg:
class file < ActiveRecord::Base
the problem is the “…does stuff”. For example, if the file is an
image it will be resized using rmagick, if it’s a video it will be
resized and re-encoded with an external encoder. I’d like to encapsulate
the specific “resize” logic somewhere and avoid long winded case/if
if type == image
…resize in rmagick
elseif type == video
…send to encoder
…do some default resize action
It would be nice to be able to have something like this:
where ExtendedClass represents a more specific version of the resize
function depending on the file type.
I think what I’m looking for is a mixture of extending (via
file.extend(Image) or file.extend(Video) for example), but that is
getting a bit messy to manage.
Any ideas? What options are available to extend or override methods in a
base class, depending on the values found in the base.
sorry for the vague explanation - it’s the end of a long day!