/usr/lib/ruby/vendor_ruby/sequel/extensions/set_overrides.rb is in ruby-sequel 4.15.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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # The set_overrides extension adds the Dataset#set_overrides and
# Dataset#set_defaults methods which provide a crude way to
# control the values used in INSERT/UPDATE statements if a hash
# of values is passed to Dataset#insert or Dataset#update.
# It is only recommended to use this for backwards compatibility.
#
# You can load this extension into specific datasets:
#
# ds = DB[:table]
# ds = ds.extension(:set_overrides)
#
# Or you can load it into all of a database's datasets, which
# is probably the desired behavior if you are using this extension:
#
# DB.extension(:set_overrides)
#
module Sequel
module SetOverrides
Dataset::NON_SQL_OPTIONS.concat([:defaults, :overrides])
Dataset.def_mutation_method(:set_defaults, :set_overrides, :module=>self)
# Set overrides/defaults for insert hashes
def insert_sql(*values)
if values.size == 1 && (vals = values.first).is_a?(Hash)
super(merge_defaults_overrides(vals))
else
super
end
end
# Set the default values for insert and update statements. The values hash passed
# to insert or update are merged into this hash, so any values in the hash passed
# to insert or update will override values passed to this method.
#
# DB[:items].set_defaults(:a=>'a', :c=>'c').insert(:a=>'d', :b=>'b')
# # INSERT INTO items (a, c, b) VALUES ('d', 'c', 'b')
def set_defaults(hash)
clone(:defaults=>(@opts[:defaults]||{}).merge(hash))
end
# Set values that override hash arguments given to insert and update statements.
# This hash is merged into the hash provided to insert or update, so values
# will override any values given in the insert/update hashes.
#
# DB[:items].set_overrides(:a=>'a', :c=>'c').insert(:a=>'d', :b=>'b')
# # INSERT INTO items (a, c, b) VALUES ('a', 'c', 'b')
def set_overrides(hash)
clone(:overrides=>hash.merge(@opts[:overrides]||{}))
end
# Set overrides/defaults for update hashes
def update_sql(values = {})
if values.is_a?(Hash)
super(merge_defaults_overrides(values))
else
super
end
end
private
# Return new hashe with merged defaults and overrides.
def merge_defaults_overrides(vals)
vals = @opts[:defaults].merge(vals) if @opts[:defaults]
vals = vals.merge(@opts[:overrides]) if @opts[:overrides]
vals
end
end
Dataset.register_extension(:set_overrides, SetOverrides)
end
|