aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/extensions
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-05-17 14:31:04 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-05-17 14:31:04 -0400
commit7032a50297fce4d7724d1735e81e5df5fd919e71 (patch)
treec52333abcc7a1454ea6ada7fe5e31e054f4e9540 /lib/arel/algebra/extensions
parentbdca9ed42ffea10aa6989ea3ecebedb424fa01ed (diff)
downloadrails-7032a50297fce4d7724d1735e81e5df5fd919e71.tar.gz
rails-7032a50297fce4d7724d1735e81e5df5fd919e71.tar.bz2
rails-7032a50297fce4d7724d1735e81e5df5fd919e71.zip
reorganized file structures
Conflicts: lib/arel.rb lib/arel/arel.rb lib/arel/engines/memory/predicates.rb lib/arel/engines/memory/relations/array.rb lib/arel/engines/sql/relations/table.rb
Diffstat (limited to 'lib/arel/algebra/extensions')
-rw-r--r--lib/arel/algebra/extensions/array.rb5
-rw-r--r--lib/arel/algebra/extensions/class.rb37
-rw-r--r--lib/arel/algebra/extensions/hash.rb7
-rw-r--r--lib/arel/algebra/extensions/object.rb15
-rw-r--r--lib/arel/algebra/extensions/pathname.rb5
5 files changed, 69 insertions, 0 deletions
diff --git a/lib/arel/algebra/extensions/array.rb b/lib/arel/algebra/extensions/array.rb
new file mode 100644
index 0000000000..5b6d6d6abd
--- /dev/null
+++ b/lib/arel/algebra/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/arel/algebra/extensions/class.rb b/lib/arel/algebra/extensions/class.rb
new file mode 100644
index 0000000000..f37898e7d7
--- /dev/null
+++ b/lib/arel/algebra/extensions/class.rb
@@ -0,0 +1,37 @@
+class Class
+ def attributes(*attrs)
+ @attributes = attrs
+ attr_reader *attrs
+ end
+
+ def deriving(*methods)
+ methods.each { |m| derive m }
+ end
+
+ def derive(method_name)
+ methods = {
+ :initialize => "
+ def #{method_name}(#{@attributes.join(',')})
+ #{@attributes.collect { |a| "@#{a} = #{a}" }.join("\n")}
+ end
+ ",
+ :== => "
+ def ==(other)
+ #{name} === other &&
+ #{@attributes.collect { |a| "@#{a} == other.#{a}" }.join(" &&\n")}
+ end
+ "
+ }
+ class_eval methods[method_name], __FILE__, __LINE__
+ end
+
+ def hash_on(delegatee)
+ define_method :eql? do |other|
+ self == other
+ end
+
+ define_method :hash do
+ @hash ||= delegatee.hash
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/algebra/extensions/hash.rb b/lib/arel/algebra/extensions/hash.rb
new file mode 100644
index 0000000000..7472b5aa73
--- /dev/null
+++ b/lib/arel/algebra/extensions/hash.rb
@@ -0,0 +1,7 @@
+class Hash
+ def bind(relation)
+ inject({}) do |bound, (key, value)|
+ bound.merge(key.bind(relation) => value.bind(relation))
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/arel/algebra/extensions/object.rb b/lib/arel/algebra/extensions/object.rb
new file mode 100644
index 0000000000..d626407dcb
--- /dev/null
+++ b/lib/arel/algebra/extensions/object.rb
@@ -0,0 +1,15 @@
+class Object
+ def bind(relation)
+ Arel::Value.new(self, relation)
+ end
+
+ def find_correlate_in(relation)
+ bind(relation)
+ end
+
+ def metaclass
+ class << self
+ self
+ end
+ end
+end
diff --git a/lib/arel/algebra/extensions/pathname.rb b/lib/arel/algebra/extensions/pathname.rb
new file mode 100644
index 0000000000..2f7e2733e7
--- /dev/null
+++ b/lib/arel/algebra/extensions/pathname.rb
@@ -0,0 +1,5 @@
+class Pathname
+ def /(path)
+ (self + path).expand_path
+ end
+end \ No newline at end of file