module Sequel::Plugins::WhitelistSecurity::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/whitelist_security.rb 67 def set_all(hash) 68 set_restricted(hash, :all) 69 end
Set all values using the entries in the hash, ignoring any setting of allowed_columns in the model.
Artist.set_allowed_columns(:num_albums) artist.set_all(name: 'Jim') artist.name # => 'Jim'
Source
# File lib/sequel/plugins/whitelist_security.rb 79 def set_only(hash, *only) 80 set_restricted(hash, only.flatten) 81 end
Set the values using the entries in the hash, only if the key is included in only. It may be a better idea to use set_fields
instead of this method.
artist.set_only({name: 'Jim'}, :name) artist.name # => 'Jim' artist.set_only({hometown: 'LA'}, :name) # Raise Error
Source
# File lib/sequel/plugins/whitelist_security.rb 88 def update_all(hash) 89 update_restricted(hash, :all) 90 end
Update all values using the entries in the hash, ignoring any setting of allowed_columns
in the model.
Artist.set_allowed_columns(:num_albums) artist.update_all(name: 'Jim') # UPDATE artists SET name = 'Jim' WHERE (id = 1)
Source
# File lib/sequel/plugins/whitelist_security.rb 100 def update_only(hash, *only) 101 update_restricted(hash, only.flatten) 102 end
Update the values using the entries in the hash, only if the key is included in only. It may be a better idea to use update_fields
instead of this method.
artist.update_only({name: 'Jim'}, :name) # UPDATE artists SET name = 'Jim' WHERE (id = 1) artist.update_only({hometown: 'LA'}, :name) # Raise Error
Private Instance Methods
Source
# File lib/sequel/plugins/whitelist_security.rb 107 def setter_methods(type) 108 if type == :default && model.allowed_columns 109 model.setter_methods 110 elsif type.is_a?(Array) 111 type.map{|x| "#{x}="} 112 elsif type == :all && primary_key && model.restrict_primary_key? 113 super + Array(primary_key).map{|x| "#{x}="} 114 else 115 super 116 end 117 end
If allowed_columns is set and set/update is called, only allow those columns.
Calls superclass method