1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

refactoring expressions to a module

This commit is contained in:
Aaron Patterson 2010-09-14 15:20:24 -07:00
parent 5d11fa9f6a
commit 188fc7a464
4 changed files with 27 additions and 31 deletions

View file

@ -1,6 +1,7 @@
require 'arel/crud' require 'arel/crud'
require 'arel/version' require 'arel/version'
require 'arel/expressions'
require 'arel/table' require 'arel/table'
require 'arel/attributes' require 'arel/attributes'
require 'arel/compatibility/wheres' require 'arel/compatibility/wheres'

View file

@ -1,6 +1,8 @@
module Arel module Arel
module Attributes module Attributes
class Attribute < Struct.new :relation, :name, :column class Attribute < Struct.new :relation, :name, :column
include Arel::Expressions
def not_eq other def not_eq other
Nodes::NotEqual.new self, other Nodes::NotEqual.new self, other
end end
@ -13,26 +15,6 @@ module Arel
Nodes::In.new self, other Nodes::In.new self, other
end end
def count distinct = false
Nodes::Count.new [self], distinct
end
def sum
Nodes::Sum.new [self], Nodes::SqlLiteral.new('sum_id')
end
def maximum
Nodes::Max.new [self], Nodes::SqlLiteral.new('max_id')
end
def minimum
Nodes::Min.new [self], Nodes::SqlLiteral.new('min_id')
end
def average
Nodes::Avg.new [self], Nodes::SqlLiteral.new('avg_id')
end
def gteq right def gteq right
Nodes::GreaterThanOrEqual.new self, right Nodes::GreaterThanOrEqual.new self, right
end end

23
lib/arel/expressions.rb Normal file
View file

@ -0,0 +1,23 @@
module Arel
module Expressions
def count distinct = false
Nodes::Count.new [self], distinct
end
def sum
Nodes::Sum.new [self], Nodes::SqlLiteral.new('sum_id')
end
def maximum
Nodes::Max.new [self], Nodes::SqlLiteral.new('max_id')
end
def minimum
Nodes::Min.new [self], Nodes::SqlLiteral.new('min_id')
end
def average
Nodes::Avg.new [self], Nodes::SqlLiteral.new('avg_id')
end
end
end

View file

@ -1,17 +1,7 @@
module Arel module Arel
module Nodes module Nodes
class SqlLiteral < String class SqlLiteral < String
def count distinct = false include Arel::Expressions
Count.new [self], distinct
end
def sum
Nodes::Sum.new [self], Nodes::SqlLiteral.new('sum_id')
end
def maximum
Nodes::Max.new [self], Nodes::SqlLiteral.new('max_id')
end
end end
end end
end end