Skip to content

Instantly share code, notes, and snippets.

@ottbot
Created September 3, 2010 10:46
Show Gist options
  • Save ottbot/563735 to your computer and use it in GitHub Desktop.
Save ottbot/563735 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sequel'
DB = Sequel.connect('mysql://test:test@localhost/test') unless defined?(DB)
[:foos].each do |t|
DB.create_table? t do
primary_key :id
String :name
end
#DB[t].truncate
end
#----------------------------------------------
module Sequel
module Plugins
module TestPlug
def self.configure(model, opts = {})
model.bar_name = opts[:bar] || "#{model.table_name}_bar"
puts model.bar_name
end
end
module ClassMethods
attr_accessor :bar_name
def inherited(subclass)
super
subclass.bar_name = bar_name
end
end
module InstanceMethods
end
end
end
#----------------------------------------------
class Foo < Sequel::Model
plugin :test_plug
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment