Created
September 3, 2010 10:46
-
-
Save ottbot/563735 to your computer and use it in GitHub Desktop.
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 '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