Sha256: a57c6063f10ad580385e6356fbb06f8b69f15565b879341d47553e1e4775a8d8

Contents?: true

Size: 786 Bytes

Versions: 23

Compression:

Stored size: 786 Bytes

Contents

module NCore
  module Lifecycle

    def errors?
      @errors.any?
    end

    def valid?
      @errors.none?
    end


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

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

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ncore-1.2.0 lib/ncore/lifecycle.rb
ncore-1.1.0 lib/ncore/lifecycle.rb
ncore-1.0.0 lib/ncore/lifecycle.rb