Sha256: 08e687b115fd3f292448247e5baf905c1cbf8c512a50f4a9d3e24056f5702d35

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'active_model'
module Sequel
  module Plugins
    # The ActiveModel plugin makes Sequel::Model objects the
    # pass the ActiveModel::Lint tests, which should
    # hopefully mean full ActiveModel compliance.  This should
    # allow the full support of Sequel::Model objects in Rails 3.
    # This plugin requires active_model in order to use
    # ActiveModel::Naming.
    module ActiveModel
      ClassMethods = ::ActiveModel::Naming

      module InstanceMethods
        # Record that an object was destroyed, for later use by
        # destroyed?
        def after_destroy
          super
          @destroyed = true
        end
        
        # Whether the object was destroyed by destroy.  Not true
        # for objects that were deleted.
        def destroyed?
          @destroyed == true
        end
        
        # An alias for new?
        def new_record?
          new?
        end

        # With the ActiveModel plugin, Sequel model objects are already
        # compliant, so this returns self.
        def to_model
          self
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sequel-3.10.0 lib/sequel/plugins/active_model.rb
sequel-3.9.0 lib/sequel/plugins/active_model.rb