1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

basic functionality for simplest active record find(id)

- messy code, to be cleaned up this weekend
This commit is contained in:
Nick Kallen 2008-03-05 22:12:21 -08:00
parent 6647a1e08e
commit 98527c8f7d
3 changed files with 31 additions and 11 deletions

View file

@ -1,4 +1,18 @@
module ActiveRelation
# this file is currently just a hack to adapt between activerecord::base which holds the connection specification
# and active relation. ultimately, this file should be in effect what the connection specification is in active record;
# that is: a spec of the database (url, password, etc.), a quoting adapter layer, and a connection pool.
class Engine
def initialize(ar = nil)
@ar = ar
end
def connection
@ar.connection
end
def method_missing(method, *args, &block)
@ar.connection.send(method, *args, &block)
end
end
end

View file

@ -1,24 +1,22 @@
require 'singleton'
module ActiveRelation
class Session
class Session
class << self
attr_accessor :instance
alias_method :manufacture, :new
def start
if @started
yield
else
begin
@started = true
@instance = new
manufacture = method(:new)
metaclass.class_eval do
define_method(:new) { @instance }
end
@instance = manufacture
metaclass.send :alias_method, :new, :instance
yield
ensure
metaclass.class_eval do
define_method(:new, &manufacture)
end
metaclass.send :alias_method, :new, :manufacture
@started = false
end
end
@ -31,8 +29,10 @@ module ActiveRelation
end
def read(select)
@read ||= {}
@read.has_key?(select) ? @read[select] : (@read[select] = select.engine.select_all(select.to_sql))
@read ||= Hash.new do |hash, select|
hash[select] = select.engine.select_all(select.to_sql)
end
@read[select]
end
def update(update)

View file

@ -91,5 +91,11 @@ module ActiveRelation
Table.new(:users, engine = Engine.new).engine.should == engine
end
end
describe '#reset' do
it "" do
pending
end
end
end
end