Module: Sequel::Plugins::WhitelistSecurity::InstanceMethods

Defined in:
lib/sequel/plugins/whitelist_security.rb

Instance Method Summary collapse

Instance Method Details

#set_all(hash) ⇒ Object

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'


67
68
69
# File 'lib/sequel/plugins/whitelist_security.rb', line 67

def set_all(hash)
  set_restricted(hash, :all)
end

#set_only(hash, *only) ⇒ Object

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


79
80
81
# File 'lib/sequel/plugins/whitelist_security.rb', line 79

def set_only(hash, *only)
  set_restricted(hash, only.flatten)
end

#update_all(hash) ⇒ Object

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)


88
89
90
# File 'lib/sequel/plugins/whitelist_security.rb', line 88

def update_all(hash)
  update_restricted(hash, :all)
end

#update_only(hash, *only) ⇒ Object

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


100
101
102
# File 'lib/sequel/plugins/whitelist_security.rb', line 100

def update_only(hash, *only)
  update_restricted(hash, only.flatten)
end