1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# frozen-string-literal: true
#
# The symbol_as_refinement extension adds a refinement that makes
# Symbol#as return Sequel::SQL::AliasedExpression instances. It's
# designed as a shortcut so that instead of:
#
# Sequel[:column].as(:alias) # column AS alias
#
# you can just write:
#
# :column.as(:alias) # column AS alias
#
# To load the extension:
#
# Sequel.extension :symbol_as_refinement
#
# To enable the refinement for the current file:
#
# using Sequel::SymbolAs
#
# If you would like this extension to be enabled globally instead
# of as a refinement, use the symbol_as extension.
#
# Related module: Sequel::SymbolAs
# :nocov:
raise(Sequel::Error, "Refinements require ruby 2.0.0 or greater") unless RUBY_VERSION >= '2.0.0'
# :nocov:
module Sequel::SymbolAs
refine Symbol do
def as(aliaz, columns=nil)
Sequel::SQL::AliasedExpression.new(self, aliaz, columns)
end
end
end
|