-
-
Save mikepack/6091652 to your computer and use it in GitHub Desktop.
Convert to mixin
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
# == Paperclip without ActiveRecord | |
# | |
# Original: https://gist.github.com/basgys/5712426 | |
require 'active_model/naming' | |
require 'active_model/callbacks' | |
require 'active_model/validations' | |
require 'paperclip' | |
require 'paperclip/glue' | |
module SimplePaperclip | |
def self.included(base) | |
base.extend ActiveModel::Naming | |
base.extend ActiveModel::Callbacks | |
base.send :include, ActiveModel::Validations | |
base.send :include, Paperclip::Glue | |
# Paperclip required callbacks | |
base.define_model_callbacks :save, only: [:after] | |
base.define_model_callbacks :destroy, only: [:before, :after] | |
end | |
# ActiveModel requirements | |
def to_model | |
self | |
end | |
def valid?() true end | |
def new_record?() true end | |
def destroyed?() true end | |
def errors | |
obj = Object.new | |
def obj.[](key) [] end | |
def obj.full_messages() [] end | |
obj | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment