Skip to content

Instantly share code, notes, and snippets.

@fbacall
Created November 30, 2023 13:15
Show Gist options
  • Save fbacall/6453ed0a7cc76eb714c373c959990bae to your computer and use it in GitHub Desktop.
Save fbacall/6453ed0a7cc76eb714c373c959990bae to your computer and use it in GitHub Desktop.
Place in db directory and run via plain `ruby`
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