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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# frozen-string-literal: true
#
# The symbol_aref extension makes Symbol#[] support Symbol,
# Sequel::SQL::Indentifier, and Sequel::SQL::QualifiedIdentifier instances,
# returning appropriate Sequel::SQL::QualifiedIdentifier instances. It's
# designed as a shortcut so that instead of:
#
# Sequel[:table][:column] # table.column
#
# you can just write:
#
# :table[:column] # table.column
#
# To load the extension:
#
# Sequel.extension :symbol_aref
#
# If you are using Ruby 2+, and you would like to use refinements, there
# is a refinement version of this in the symbol_aref_refinement extension.
#
# Related module: Sequel::SymbolAref
if RUBY_VERSION >= '2.0'
module Sequel::SymbolAref
def [](v)
case v
when Symbol, Sequel::SQL::Identifier, Sequel::SQL::QualifiedIdentifier
Sequel::SQL::QualifiedIdentifier.new(self, v)
else
super
end
end
end
class Symbol
prepend Sequel::SymbolAref
end
# :nocov:
else
class Symbol
if method_defined?(:[])
alias_method :aref_before_sequel, :[]
end
def [](v)
case v
when Symbol, Sequel::SQL::Identifier, Sequel::SQL::QualifiedIdentifier
Sequel::SQL::QualifiedIdentifier.new(self, v)
else
aref_before_sequel(v)
end
end
end
end
# :nocov:
|