Skip to content

Instantly share code, notes, and snippets.

@ippeiukai
Last active November 25, 2015 09:47
Show Gist options
  • Save ippeiukai/4623b9e11b0d283a3cf9 to your computer and use it in GitHub Desktop.
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.
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