/usr/lib/ruby/vendor_ruby/sequel/extensions/query.rb is in ruby-sequel 3.33.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # The query extension adds Sequel::Dataset#query which allows
# a different way to construct queries instead of the usual
# method chaining.
module Sequel
class Database
# Return a dataset modified by the query block
def query(&block)
dataset.query(&block)
end
end
class Dataset
# Translates a query block into a dataset. Query blocks can be useful
# when expressing complex SELECT statements, e.g.:
#
# dataset = DB[:items].query do
# select :x, :y, :z
# filter{|o| (o.x > 1) & (o.y > 2)}
# order :z.desc
# end
#
# Which is the same as:
#
# dataset = DB[:items].select(:x, :y, :z).filter{|o| (o.x > 1) & (o.y > 2)}.order(:z.desc)
#
# Note that inside a call to query, you cannot call each, insert, update,
# or delete (or any method that calls those), or Sequel will raise an
# error.
def query(&block)
copy = clone({})
copy.extend(QueryBlockCopy)
copy.instance_eval(&block)
clone(copy.opts)
end
# Module used by Dataset#query that has the effect of making all
# dataset methods into !-style methods that modify the receiver.
module QueryBlockCopy
%w'each insert update delete'.each do |meth|
define_method(meth){|*args| raise Error, "##{meth} cannot be invoked inside a query block."}
end
# Merge the given options into the receiver's options and return the receiver
# instead of cloning the receiver.
def clone(opts = {})
@opts.merge!(opts)
self
end
end
end
end
|