Module: NCore::Lifecycle

Defined in:
lib/ncore/lifecycle.rb

Instance Method Summary collapse

Instance Method Details

#errors?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/ncore/lifecycle.rb', line 4

def errors?
  @errors.any?
end

#save(update_params = {}) ⇒ Object Also known as: update_attributes



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ncore/lifecycle.rb', line 13

def save(update_params={})
  if id.present?
    if respond_to? :update, true
      update(update_params)
    else
      raise self.class.module_parent::Error, "Updating #{self.class.name} objects is not supported."
    end
  else
    if respond_to? :create, true
      create(update_params)
    else
      raise self.class.module_parent::Error, "Creating #{self.class.name} objects is not supported."
    end
  end
end

#save!(update_params = {}) ⇒ Object Also known as: update_attributes!



30
31
32
# File 'lib/ncore/lifecycle.rb', line 30

def save!(update_params={})
  save(update_params) || raise(self.class.module_parent::RecordInvalid, self)
end

#valid?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/ncore/lifecycle.rb', line 8

def valid?
  @errors.none?
end