diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-05 22:12:21 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-05 22:12:21 -0800 |
commit | 98527c8f7dd64f086895c1576fb33e8b91071142 (patch) | |
tree | 5dba9641dc4a45f4324e9c1cdb9f49475d451f9c /lib | |
parent | 6647a1e08eb9dc3512628882bcf60d421df74228 (diff) | |
download | rails-98527c8f7dd64f086895c1576fb33e8b91071142.tar.gz rails-98527c8f7dd64f086895c1576fb33e8b91071142.tar.bz2 rails-98527c8f7dd64f086895c1576fb33e8b91071142.zip |
basic functionality for simplest active record find(id)
- messy code, to be cleaned up this weekend
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/engines/engine.rb | 14 | ||||
-rw-r--r-- | lib/active_relation/sessions/session.rb | 22 |
2 files changed, 25 insertions, 11 deletions
diff --git a/lib/active_relation/engines/engine.rb b/lib/active_relation/engines/engine.rb index 36b77b886e..d5b312607e 100644 --- a/lib/active_relation/engines/engine.rb +++ b/lib/active_relation/engines/engine.rb @@ -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
\ No newline at end of file diff --git a/lib/active_relation/sessions/session.rb b/lib/active_relation/sessions/session.rb index 0724abc5a7..4bdbe69978 100644 --- a/lib/active_relation/sessions/session.rb +++ b/lib/active_relation/sessions/session.rb @@ -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) |