Sha256: f9e0e7874a02d5f78c2ba0c81beb0d25db298e6ab3d665a60baa9166f7c5b77c

Contents?: true

Size: 1.26 KB

Versions: 97

Compression:

Stored size: 1.26 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
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

Version data entries

97 entries across 80 versions & 2 rubygems

Version Path
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/sequel-5.59.0/lib/sequel/extensions/symbol_aref.rb
sequel-5.59.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.58.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.57.0 lib/sequel/extensions/symbol_aref.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/sequel-5.56.0/lib/sequel/extensions/symbol_aref.rb
sequel-5.56.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.55.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.54.0 lib/sequel/extensions/symbol_aref.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/sequel-5.53.0/lib/sequel/extensions/symbol_aref.rb
sequel-5.53.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.52.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.51.0 lib/sequel/extensions/symbol_aref.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/sequel-5.50.0/lib/sequel/extensions/symbol_aref.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/symbol_aref.rb
sequel-5.50.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.49.0 lib/sequel/extensions/symbol_aref.rb
sequel-5.48.0 lib/sequel/extensions/symbol_aref.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/sequel-5.47.0/lib/sequel/extensions/symbol_aref.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/extensions/symbol_aref.rb
sequel-5.47.0 lib/sequel/extensions/symbol_aref.rb