module Paperdragon::Model::ClassMethods

Public Instance Methods

processable(name, attachment_class=Attachment) click to toggle source
# File lib/paperdragon/model.rb, line 9
def processable(name, attachment_class=Attachment)
  include attachment_accessor_for(name, attachment_class)
end

Private Instance Methods

attachment_accessor_for(name, attachment_class) click to toggle source

Creates Avatar#image that returns a Paperdragon::File instance.

# File lib/paperdragon/model.rb, line 15
def attachment_accessor_for(name, attachment_class)
  mod = Module.new do # TODO: abstract that into Uber, we use it everywhere.
    define_method name do |file=nil, options={}, &block|
      attachment = attachment_class.new(public_send("#{name}_meta_data"),
                                        options.merge(model: self))

      return attachment unless file or block

      # run the task block and save the returned new metadata in the model.
      self.public_send("#{name}_meta_data=", attachment.task(*[file], &block))
    end
  end
end