Module: Sequel::SetOverrides

Defined in:
lib/sequel/extensions/set_overrides.rb

Instance Method Summary collapse

Instance Method Details

#insert_sql(*values) ⇒ Object

Set overrides/defaults for insert hashes



24
25
26
27
28
29
30
# File 'lib/sequel/extensions/set_overrides.rb', line 24

def insert_sql(*values)
  if values.size == 1 && (vals = values.first).is_a?(Hash)
    super(merge_defaults_overrides(vals))
  else
    super
  end
end

#set_defaults(hash) ⇒ Object

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')


38
39
40
# File 'lib/sequel/extensions/set_overrides.rb', line 38

def set_defaults(hash)
  clone(:defaults=>(@opts[:defaults]||{}).merge(hash))
end

#set_overrides(hash) ⇒ Object

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')


48
49
50
# File 'lib/sequel/extensions/set_overrides.rb', line 48

def set_overrides(hash)
  clone(:overrides=>hash.merge(@opts[:overrides]||{}))
end

#update_sql(values = {}) ⇒ Object

Set overrides/defaults for update hashes



53
54
55
56
57
58
59
# File 'lib/sequel/extensions/set_overrides.rb', line 53

def update_sql(values = {})
  if values.is_a?(Hash)
    super(merge_defaults_overrides(values))
  else
    super
  end
end