Module: NCore::Update::ClassMethods

Defined in:
lib/ncore/methods/update.rb

Instance Method Summary collapse

Instance Method Details

#update(id, attribs) ⇒ Object

always returns a new object; check .errors? or .valid? to see how it went

Raises:

  • (module_parent::RecordNotFound)


15
16
17
18
19
20
# File 'lib/ncore/methods/update.rb', line 15

def update(id, attribs)
  raise(module_parent::RecordNotFound, "Cannot update id=nil") if id.blank?
  obj = new({id: id})
  obj.update attribs
  obj
end

#update!(id, attribs) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ncore/methods/update.rb', line 6

def update!(id, attribs)
  obj = update(id, attribs)
  if obj.errors?
    raise module_parent::RecordInvalid, obj
  end
  obj
end