From 52e8aff146c162986566d3e03852395729d7c24d Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Wed, 30 Sep 2009 23:23:46 -0400 Subject: Move extensions directories to core_extensions --- lib/arel/algebra.rb | 2 +- lib/arel/algebra/core_extensions.rb | 4 +++ lib/arel/algebra/core_extensions/class.rb | 32 +++++++++++++++++++++++ lib/arel/algebra/core_extensions/hash.rb | 11 ++++++++ lib/arel/algebra/core_extensions/object.rb | 17 ++++++++++++ lib/arel/algebra/core_extensions/symbol.rb | 9 +++++++ lib/arel/algebra/extensions.rb | 4 --- lib/arel/algebra/extensions/class.rb | 32 ----------------------- lib/arel/algebra/extensions/hash.rb | 11 -------- lib/arel/algebra/extensions/object.rb | 17 ------------ lib/arel/algebra/extensions/symbol.rb | 9 ------- lib/arel/engines/sql.rb | 2 +- lib/arel/engines/sql/core_extensions.rb | 4 +++ lib/arel/engines/sql/core_extensions/array.rb | 16 ++++++++++++ lib/arel/engines/sql/core_extensions/nil_class.rb | 11 ++++++++ lib/arel/engines/sql/core_extensions/object.rb | 15 +++++++++++ lib/arel/engines/sql/core_extensions/range.rb | 15 +++++++++++ lib/arel/engines/sql/extensions.rb | 4 --- lib/arel/engines/sql/extensions/array.rb | 16 ------------ lib/arel/engines/sql/extensions/nil_class.rb | 11 -------- lib/arel/engines/sql/extensions/object.rb | 15 ----------- lib/arel/engines/sql/extensions/range.rb | 15 ----------- 22 files changed, 136 insertions(+), 136 deletions(-) create mode 100644 lib/arel/algebra/core_extensions.rb create mode 100644 lib/arel/algebra/core_extensions/class.rb create mode 100644 lib/arel/algebra/core_extensions/hash.rb create mode 100644 lib/arel/algebra/core_extensions/object.rb create mode 100644 lib/arel/algebra/core_extensions/symbol.rb delete mode 100644 lib/arel/algebra/extensions.rb delete mode 100644 lib/arel/algebra/extensions/class.rb delete mode 100644 lib/arel/algebra/extensions/hash.rb delete mode 100644 lib/arel/algebra/extensions/object.rb delete mode 100644 lib/arel/algebra/extensions/symbol.rb create mode 100644 lib/arel/engines/sql/core_extensions.rb create mode 100644 lib/arel/engines/sql/core_extensions/array.rb create mode 100644 lib/arel/engines/sql/core_extensions/nil_class.rb create mode 100644 lib/arel/engines/sql/core_extensions/object.rb create mode 100644 lib/arel/engines/sql/core_extensions/range.rb delete mode 100644 lib/arel/engines/sql/extensions.rb delete mode 100644 lib/arel/engines/sql/extensions/array.rb delete mode 100644 lib/arel/engines/sql/extensions/nil_class.rb delete mode 100644 lib/arel/engines/sql/extensions/object.rb delete mode 100644 lib/arel/engines/sql/extensions/range.rb diff --git a/lib/arel/algebra.rb b/lib/arel/algebra.rb index c206fea0b0..319f8fc242 100644 --- a/lib/arel/algebra.rb +++ b/lib/arel/algebra.rb @@ -1,4 +1,4 @@ -require 'arel/algebra/extensions' +require 'arel/algebra/core_extensions' require 'arel/algebra/predicates' require 'arel/algebra/relations' require 'arel/algebra/primitives' diff --git a/lib/arel/algebra/core_extensions.rb b/lib/arel/algebra/core_extensions.rb new file mode 100644 index 0000000000..bce86d04ba --- /dev/null +++ b/lib/arel/algebra/core_extensions.rb @@ -0,0 +1,4 @@ +require 'arel/algebra/core_extensions/object' +require 'arel/algebra/core_extensions/class' +require 'arel/algebra/core_extensions/symbol' +require 'arel/algebra/core_extensions/hash' 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 diff --git a/lib/arel/algebra/extensions.rb b/lib/arel/algebra/extensions.rb deleted file mode 100644 index bc8edd3274..0000000000 --- a/lib/arel/algebra/extensions.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'arel/algebra/extensions/object' -require 'arel/algebra/extensions/class' -require 'arel/algebra/extensions/symbol' -require 'arel/algebra/extensions/hash' diff --git a/lib/arel/algebra/extensions/class.rb b/lib/arel/algebra/extensions/class.rb deleted file mode 100644 index d0894931da..0000000000 --- a/lib/arel/algebra/extensions/class.rb +++ /dev/null @@ -1,32 +0,0 @@ -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/extensions/hash.rb b/lib/arel/algebra/extensions/hash.rb deleted file mode 100644 index c64225f685..0000000000 --- a/lib/arel/algebra/extensions/hash.rb +++ /dev/null @@ -1,11 +0,0 @@ -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/extensions/object.rb b/lib/arel/algebra/extensions/object.rb deleted file mode 100644 index 85a4d951a4..0000000000 --- a/lib/arel/algebra/extensions/object.rb +++ /dev/null @@ -1,17 +0,0 @@ -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/extensions/symbol.rb b/lib/arel/algebra/extensions/symbol.rb deleted file mode 100644 index f575ad533a..0000000000 --- a/lib/arel/algebra/extensions/symbol.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Arel - module SymbolExtensions - def to_attribute(relation) - Arel::Attribute.new(relation, self) - end - - Symbol.send(:include, self) - end -end diff --git a/lib/arel/engines/sql.rb b/lib/arel/engines/sql.rb index f31cfc7dac..dc40428b77 100644 --- a/lib/arel/engines/sql.rb +++ b/lib/arel/engines/sql.rb @@ -3,5 +3,5 @@ require 'arel/engines/sql/relations' require 'arel/engines/sql/primitives' require 'arel/engines/sql/predicates' require 'arel/engines/sql/formatters' -require 'arel/engines/sql/extensions' +require 'arel/engines/sql/core_extensions' require 'arel/engines/sql/christener' diff --git a/lib/arel/engines/sql/core_extensions.rb b/lib/arel/engines/sql/core_extensions.rb new file mode 100644 index 0000000000..c8d9ec239e --- /dev/null +++ b/lib/arel/engines/sql/core_extensions.rb @@ -0,0 +1,4 @@ +require 'arel/engines/sql/core_extensions/object' +require 'arel/engines/sql/core_extensions/array' +require 'arel/engines/sql/core_extensions/range' +require 'arel/engines/sql/core_extensions/nil_class' diff --git a/lib/arel/engines/sql/core_extensions/array.rb b/lib/arel/engines/sql/core_extensions/array.rb new file mode 100644 index 0000000000..80041cb5f3 --- /dev/null +++ b/lib/arel/engines/sql/core_extensions/array.rb @@ -0,0 +1,16 @@ +module Arel + module Sql + module ArrayExtensions + def to_sql(formatter = nil) + "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")" + end + + def inclusion_predicate_sql + "IN" + end + + Array.send(:include, self) + end + end +end + diff --git a/lib/arel/engines/sql/core_extensions/nil_class.rb b/lib/arel/engines/sql/core_extensions/nil_class.rb new file mode 100644 index 0000000000..c3dbc8cd76 --- /dev/null +++ b/lib/arel/engines/sql/core_extensions/nil_class.rb @@ -0,0 +1,11 @@ +module Arel + module Sql + module NilClassExtensions + def equality_predicate_sql + 'IS' + end + + NilClass.send(:include, self) + end + end +end diff --git a/lib/arel/engines/sql/core_extensions/object.rb b/lib/arel/engines/sql/core_extensions/object.rb new file mode 100644 index 0000000000..9f15dff771 --- /dev/null +++ b/lib/arel/engines/sql/core_extensions/object.rb @@ -0,0 +1,15 @@ +module Arel + module Sql + module ObjectExtensions + def to_sql(formatter) + formatter.scalar self + end + + def equality_predicate_sql + '=' + end + + Object.send(:include, self) + end + end +end diff --git a/lib/arel/engines/sql/core_extensions/range.rb b/lib/arel/engines/sql/core_extensions/range.rb new file mode 100644 index 0000000000..46124f8865 --- /dev/null +++ b/lib/arel/engines/sql/core_extensions/range.rb @@ -0,0 +1,15 @@ +module Arel + module Sql + module RangeExtensions + def to_sql(formatter = nil) + formatter.range self.begin, self.end + end + + def inclusion_predicate_sql + "BETWEEN" + end + + Range.send(:include, self) + end + end +end diff --git a/lib/arel/engines/sql/extensions.rb b/lib/arel/engines/sql/extensions.rb deleted file mode 100644 index 1ea31bc140..0000000000 --- a/lib/arel/engines/sql/extensions.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'arel/engines/sql/extensions/object' -require 'arel/engines/sql/extensions/array' -require 'arel/engines/sql/extensions/range' -require 'arel/engines/sql/extensions/nil_class' diff --git a/lib/arel/engines/sql/extensions/array.rb b/lib/arel/engines/sql/extensions/array.rb deleted file mode 100644 index 80041cb5f3..0000000000 --- a/lib/arel/engines/sql/extensions/array.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Arel - module Sql - module ArrayExtensions - def to_sql(formatter = nil) - "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")" - end - - def inclusion_predicate_sql - "IN" - end - - Array.send(:include, self) - end - end -end - diff --git a/lib/arel/engines/sql/extensions/nil_class.rb b/lib/arel/engines/sql/extensions/nil_class.rb deleted file mode 100644 index c3dbc8cd76..0000000000 --- a/lib/arel/engines/sql/extensions/nil_class.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Arel - module Sql - module NilClassExtensions - def equality_predicate_sql - 'IS' - end - - NilClass.send(:include, self) - end - end -end diff --git a/lib/arel/engines/sql/extensions/object.rb b/lib/arel/engines/sql/extensions/object.rb deleted file mode 100644 index 9f15dff771..0000000000 --- a/lib/arel/engines/sql/extensions/object.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Arel - module Sql - module ObjectExtensions - def to_sql(formatter) - formatter.scalar self - end - - def equality_predicate_sql - '=' - end - - Object.send(:include, self) - end - end -end diff --git a/lib/arel/engines/sql/extensions/range.rb b/lib/arel/engines/sql/extensions/range.rb deleted file mode 100644 index 46124f8865..0000000000 --- a/lib/arel/engines/sql/extensions/range.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Arel - module Sql - module RangeExtensions - def to_sql(formatter = nil) - formatter.range self.begin, self.end - end - - def inclusion_predicate_sql - "BETWEEN" - end - - Range.send(:include, self) - end - end -end -- cgit v1.2.3