aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_relation/extensions
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-07 18:37:20 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-01-07 18:37:20 -0800
commit311f5f8eb588d4cde051762ace87a61425300bec (patch)
tree5e087ddd6257ad793c225555a6e48ad17bbdde70 /lib/active_relation/extensions
parentd43a4e9fc1316fc9eb8ff087c52c7ca7a475c041 (diff)
downloadrails-311f5f8eb588d4cde051762ace87a61425300bec.tar.gz
rails-311f5f8eb588d4cde051762ace87a61425300bec.tar.bz2
rails-311f5f8eb588d4cde051762ace87a61425300bec.zip
minor
Diffstat (limited to 'lib/active_relation/extensions')
-rw-r--r--lib/active_relation/extensions/array.rb5
-rw-r--r--lib/active_relation/extensions/base.rb47
-rw-r--r--lib/active_relation/extensions/hash.rb13
-rw-r--r--lib/active_relation/extensions/object.rb12
-rw-r--r--lib/active_relation/extensions/range.rb0
5 files changed, 77 insertions, 0 deletions
diff --git a/lib/active_relation/extensions/array.rb b/lib/active_relation/extensions/array.rb
new file mode 100644
index 0000000000..5b6d6d6abd
--- /dev/null
+++ b/lib/active_relation/extensions/array.rb
@@ -0,0 +1,5 @@
+class Array
+ def to_hash
+ Hash[*flatten]
+ end
+end \ No newline at end of file
diff --git a/lib/active_relation/extensions/base.rb b/lib/active_relation/extensions/base.rb
new file mode 100644
index 0000000000..0dbdef703f
--- /dev/null
+++ b/lib/active_relation/extensions/base.rb
@@ -0,0 +1,47 @@
+class ActiveRecord::Base
+ class << self
+ def cache
+ @identity_map ||= IdentityMap.new
+ end
+
+ def relation
+ @relation ||= TableRelation.new(table_name)
+ end
+ end
+
+ class IdentityMap
+ def initialize
+ @map = {}
+ end
+
+ def get(record, &block)
+ @map[record] ||= yield
+ end
+ end
+end
+
+class ActiveRecord::Associations::BelongsToAssociation
+ def instantiate(record, joins = [])
+ @target = proxy_reflection.klass.instantiate(record, joins)
+ loaded
+ end
+
+ # this basically disables belongs_to from loading themselves
+ def reload
+ @target = 'hack'
+ end
+end
+
+class ActiveRecord::Associations::AssociationCollection
+ def instantiate(record, joins = [])
+ @target << proxy_reflection.klass.instantiate(record, joins)
+ loaded # technically, this isn't true. doesn't matter though
+ end
+end
+
+class ActiveRecord::Associations::HasManyThroughAssociation
+ def instantiate(record, joins = [])
+ @target << proxy_reflection.klass.instantiate(record, joins)
+ loaded # again, not really true.
+ end
+end \ No newline at end of file
diff --git a/lib/active_relation/extensions/hash.rb b/lib/active_relation/extensions/hash.rb
new file mode 100644
index 0000000000..f643ac17ab
--- /dev/null
+++ b/lib/active_relation/extensions/hash.rb
@@ -0,0 +1,13 @@
+class Hash
+ def alias(&block)
+ inject({}) do |aliased, (key, value)|
+ aliased.merge(yield(key) => value)
+ end
+ end
+
+ def to_sql(builder = ValuesBuilder.new)
+ builder.call do
+ row *values
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb
new file mode 100644
index 0000000000..c241581f86
--- /dev/null
+++ b/lib/active_relation/extensions/object.rb
@@ -0,0 +1,12 @@
+class Object
+ def qualify
+ self
+ end
+
+ def to_sql(builder = EqualsConditionBuilder.new)
+ me = self
+ builder.call do
+ value me.to_s
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/active_relation/extensions/range.rb b/lib/active_relation/extensions/range.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/active_relation/extensions/range.rb