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 56 57 58 59 60
|
# frozen-string-literal: true
#
# The s extension adds Sequel::S, a module containing a private #S
# method that calls Sequel.expr. It's designed as a shortcut so
# that instead of:
#
# Sequel.expr(:column) + 1
# # or
# Sequel.expr{column + 1}
#
# you can just write:
#
# S(:column) + 1
# # or
# S{column + 1}
#
# To load the extension:
#
# Sequel.extension :s
#
# Then you can include the Sequel::S module into whatever classes or
# objects you care about:
#
# Sequel::Model.send(:include, Sequel::S) # available in model instance methods
# Sequel::Model.extend(Sequel::S) # available in model class methods
# Sequel::Dataset.send(:include, Sequel::S) # available in dataset methods
#
# or just into Object if you want it available everywhere:
#
# Object.send(:include, Sequel::S)
#
# If you are using Ruby 2+, and you would like to use refinements, you
# can use Sequel::S as a refinement, in which case the private #S method
# will be available on all objects while the refinement is active.
#
# using Sequel::S
#
# S(:column) + 1
#
# Related module: Sequel::S
#
module Sequel::S
private
# Delegate to Sequel.expr
def S(*a, &block)
Sequel.expr(*a, &block)
end
# :nocov:
if RUBY_VERSION >= '2.0.0'
include_meth = RUBY_VERSION >= '3.1' ? :import_methods : :include
# :nocov:
refine Object do
send include_meth, Sequel::S
end
end
end
|