Last active
November 25, 2015 09:47
-
-
Save ippeiukai/4623b9e11b0d283a3cf9 to your computer and use it in GitHub Desktop.
Monkey patch to Sequel (http://github.com/jeremyevans/sequel) that lets you cleanly create an abstract model.
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
require 'sequel/model' | |
module Sequel | |
class << self | |
# abstract model needs to avoid inherited callback | |
# (see https://groups.google.com/forum/#!msg/sequel-talk/OG5ti9JAJIE/p1iqO57cwqwJ) | |
# MyAbstractModel = Sequel.new_abstract_model do | |
# # ... your common stuff ... | |
# end | |
def new_abstract_model(abstract_super_model = Sequel::Model, &block) | |
if (abstract_super_model.dataset rescue nil) | |
raise(Error, "#{abstract_super_model} is not an abstract model.") | |
end | |
Class.new(abstract_super_model, &block) | |
end | |
# MyAbstractModel = Sequel::AbstractModel() do | |
# # ... your common stuff ... | |
# end | |
alias_method :AbstractModel, :new_abstract_model | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment