Sha256: ad0db299dcd8579341bb7620bafbc35419c9b0d52708df998d00742ecc8763e7

Contents?: true

Size: 441 Bytes

Versions: 5

Compression:

Stored size: 441 Bytes

Contents

require 'active_support/concern'

module ActiveRecordNullObject
  module NullObject
    extend ActiveSupport::Concern

    included do
      validate :unsavable
    end

    def id
      nil
    end

    def nil?
      true
    end

    def empty?
      true
    end

    def blank?
      true
    end

    def present?
      false
    end

    def unsavable
      errors.add(:base, "is a null object and can't be saved")
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord_null_object-0.8.0 lib/activerecord_null_object/null_object.rb
activerecord_null_object-0.7.0 lib/activerecord_null_object/null_object.rb
activerecord_null_object-0.6.0 lib/activerecord_null_object/null_object.rb
activerecord_null_object-0.5.0 lib/activerecord_null_object/null_object.rb
activerecord_null_object-0.4.0 lib/activerecord_null_object/null_object.rb