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/version'
require 'arel/expressions'
require 'arel/table'
require 'arel/attributes'
require 'arel/compatibility/wheres'

View file

@ -1,6 +1,8 @@
module Arel
module Attributes
class Attribute < Struct.new :relation, :name, :column
include Arel::Expressions
def not_eq other
Nodes::NotEqual.new self, other
end
@ -13,26 +15,6 @@ module Arel
Nodes::In.new self, other
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
Nodes::GreaterThanOrEqual.new self, right
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 Nodes
class SqlLiteral < String
def count distinct = false
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
include Arel::Expressions
end
end
end