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-2.3.3 lib/ncore/lifecycle.rb
ncore-2.3.2 lib/ncore/lifecycle.rb
ncore-2.3.1 lib/ncore/lifecycle.rb
ncore-2.3.0 lib/ncore/lifecycle.rb
ncore-2.2.2 lib/ncore/lifecycle.rb
ncore-2.2.1 lib/ncore/lifecycle.rb
ncore-2.2.0 lib/ncore/lifecycle.rb
ncore-2.1.2 lib/ncore/lifecycle.rb
ncore-2.1.1 lib/ncore/lifecycle.rb
ncore-2.1.0 lib/ncore/lifecycle.rb
ncore-2.0.8 lib/ncore/lifecycle.rb
ncore-2.0.7 lib/ncore/lifecycle.rb
ncore-2.0.6 lib/ncore/lifecycle.rb
ncore-2.0.5 lib/ncore/lifecycle.rb
ncore-2.0.4 lib/ncore/lifecycle.rb
ncore-2.0.3 lib/ncore/lifecycle.rb
ncore-2.0.2 lib/ncore/lifecycle.rb
ncore-2.0.1 lib/ncore/lifecycle.rb
ncore-2.0.0 lib/ncore/lifecycle.rb
ncore-1.2.1 lib/ncore/lifecycle.rb