Created
November 30, 2023 13:15
-
-
Save fbacall/6453ed0a7cc76eb714c373c959990bae to your computer and use it in GitHub Desktop.
Place in db directory and run via plain `ruby`
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
module ActiveRecord | |
class Schema | |
attr_reader :users, :people | |
def initialize | |
@people = [] | |
@users = [] | |
end | |
def self.define(*args, &block) | |
a = new | |
a.instance_eval(&block) | |
puts "=== User references ===" | |
puts a.users | |
puts | |
puts "=== Person references ===" | |
puts a.people | |
puts | |
end | |
class Table | |
attr_reader :person, :user | |
def initialize | |
@user = false | |
@person = false | |
end | |
def method_missing(method, *args) | |
@user ||= (args.first == 'user_id') | |
@person ||= (args.first == 'person_id') | |
end | |
end | |
def create_table(name, *args) | |
t = Table.new | |
yield t | |
@users << name if t.user | |
@people << name if t.person | |
end | |
def method_missing(method, *args); end | |
end | |
end | |
require_relative './schema.rb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment