Sha256: 83d68a877abc0ffe5bc2f65edf8e7ed558139ae3123e53f116e63ac710f2c28f

Contents?: true

Size: 1.28 KB

Versions: 30

Compression:

Stored size: 1.28 KB

Contents

# 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:

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
sequel-5.86.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.85.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.84.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.83.1 lib/sequel/extensions/symbol_aref.rb
sequel-5.83.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.82.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.81.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.80.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.79.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.78.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.77.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.76.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.75.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.74.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.73.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.72.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.71.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.70.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.69.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.68.0 lib/sequel/extensions/symbol_aref.rb