Module: BaseModel

Extended by:
ActiveSupport::Concern
Included in:
Comment, Note, Page, Photo, Reply, Site, Topic, User
Defined in:
app/models/concerns/base_model.rb

Instance Method Summary collapse

Instance Method Details

#pull(hash) ⇒ Object

FIXME: 需要原子化操作


24
25
26
27
28
29
30
31
32
# File 'app/models/concerns/base_model.rb', line 24

def pull(hash)
  hash.each_key do |key|
    self.send("#{key}_will_change!")
    old_val = self[key]
    return true if old_val.blank?
    old_val.delete(hash[key].to_i)
    update_attributes(key => old_val)
  end
end

#push(hash) ⇒ Object

FIXME: 需要原子化操作


13
14
15
16
17
18
19
20
21
# File 'app/models/concerns/base_model.rb', line 13

def push(hash)
  hash.each_key do |key|
    self.send("#{key}_will_change!")
    old_val = self[key] || []
    old_val << hash[key].to_i
    old_val.uniq!
    update_attributes(key => old_val)
  end
end