Class: Sequel::Model

Inherits:
Object show all
Defined in:
lib/egalite/sequel_helper.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject



14
15
16
17
18
# File 'lib/egalite/sequel_helper.rb', line 14

def to_hash
  hash = {}
  self.each { |k,v| hash[k] = v }
  hash
end

#update_with(hash, *selection) ⇒ Object



3
4
5
6
7
# File 'lib/egalite/sequel_helper.rb', line 3

def update_with(hash, *selection)
  data = {}
  selection.flatten.each { |k| data[k] = hash[k] || hash[k.to_sym] }
  update(data)
end

#update_without(hash, *selection) ⇒ Object



8
9
10
11
12
13
# File 'lib/egalite/sequel_helper.rb', line 8

def update_without(hash, *selection)
  hash = hash.clone
  selection.flatten.each { |k| hash.delete(k.to_s) if hash.key?(k.to_s) }
  selection.flatten.each { |k| hash.delete(k.to_sym) if hash.key?(k.to_sym) }
  update(hash)
end