aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/core_extensions
diff options
context:
space:
mode:
authorBryan Helmkamp <bryan@brynary.com>2009-09-30 23:23:46 -0400
committerBryan Helmkamp <bryan@brynary.com>2009-09-30 23:23:46 -0400
commit52e8aff146c162986566d3e03852395729d7c24d (patch)
tree1d04e0a73a88b0bf5e091f26ce7ba8c353aeb37d /lib/arel/algebra/core_extensions
parent836a57732c6ddd3842f1bf50e687049a098f7383 (diff)
downloadrails-52e8aff146c162986566d3e03852395729d7c24d.tar.gz
rails-52e8aff146c162986566d3e03852395729d7c24d.tar.bz2
rails-52e8aff146c162986566d3e03852395729d7c24d.zip
Move extensions directories to core_extensions
Diffstat (limited to 'lib/arel/algebra/core_extensions')
-rw-r--r--lib/arel/algebra/core_extensions/class.rb32
-rw-r--r--lib/arel/algebra/core_extensions/hash.rb11
-rw-r--r--lib/arel/algebra/core_extensions/object.rb17
-rw-r--r--lib/arel/algebra/core_extensions/symbol.rb9
4 files changed, 69 insertions, 0 deletions
diff --git a/lib/arel/algebra/core_extensions/class.rb b/lib/arel/algebra/core_extensions/class.rb
new file mode 100644
index 0000000000..d0894931da
--- /dev/null
+++ b/lib/arel/algebra/core_extensions/class.rb
@@ -0,0 +1,32 @@
+module Arel
+ module ClassExtensions
+ 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
+
+ Class.send(:include, self)
+ end
+end
+
diff --git a/lib/arel/algebra/core_extensions/hash.rb b/lib/arel/algebra/core_extensions/hash.rb
new file mode 100644
index 0000000000..c64225f685
--- /dev/null
+++ b/lib/arel/algebra/core_extensions/hash.rb
@@ -0,0 +1,11 @@
+module Arel
+ module HashExtensions
+ def bind(relation)
+ inject({}) do |bound, (key, value)|
+ bound.merge(key.bind(relation) => value.bind(relation))
+ end
+ end
+
+ Hash.send(:include, self)
+ end
+end
diff --git a/lib/arel/algebra/core_extensions/object.rb b/lib/arel/algebra/core_extensions/object.rb
new file mode 100644
index 0000000000..85a4d951a4
--- /dev/null
+++ b/lib/arel/algebra/core_extensions/object.rb
@@ -0,0 +1,17 @@
+module Arel
+ module ObjectExtensions
+ def bind(relation)
+ Arel::Value.new(self, relation)
+ end
+
+ def find_correlate_in(relation)
+ bind(relation)
+ end
+
+ def let
+ yield(self)
+ end
+
+ Object.send(:include, self)
+ end
+end
diff --git a/lib/arel/algebra/core_extensions/symbol.rb b/lib/arel/algebra/core_extensions/symbol.rb
new file mode 100644
index 0000000000..f575ad533a
--- /dev/null
+++ b/lib/arel/algebra/core_extensions/symbol.rb
@@ -0,0 +1,9 @@
+module Arel
+ module SymbolExtensions
+ def to_attribute(relation)
+ Arel::Attribute.new(relation, self)
+ end
+
+ Symbol.send(:include, self)
+ end
+end