Sha256: b202ee4f2e47f6bf54056e81e0c8b61eb37ac666f50e84d1404b2a932f4efee7

Contents?: true

Size: 886 Bytes

Versions: 50

Compression:

Stored size: 886 Bytes

Contents

require 'active_support/core_ext/module/aliasing'

module MongoModel
  module RecordStatus
    extend ActiveSupport::Concern
    
    included do
      alias_method_chain :initialize, :record_status
    end
    
    def new_record?
      @_new_record
    end
    
    def destroyed?
      @_destroyed
    end
    
    def initialize_with_record_status(*args, &block)
      set_new_record(true)
      set_destroyed(false)
      
      initialize_without_record_status(*args, &block)
    end
    
  protected
    def set_new_record(value)
      set_record_status(:new_record, value)
    end
    
    def set_destroyed(value)
      set_record_status(:destroyed, value)
    end
  
  private
    def set_record_status(type, value)
      instance_variable_set("@_#{type}", value)
      embedded_documents.each { |doc| doc.send(:set_record_status, type, value) }
      value
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
mongomodel-0.5.5 lib/mongomodel/concerns/record_status.rb
mongomodel-0.5.4 lib/mongomodel/concerns/record_status.rb
mongomodel-0.5.3 lib/mongomodel/concerns/record_status.rb
mongomodel-0.5.2 lib/mongomodel/concerns/record_status.rb
mongomodel-0.5.1 lib/mongomodel/concerns/record_status.rb
mongomodel-0.5.0 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.9 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.8 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.7 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.6 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.5 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.4 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.3 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.2 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.1 lib/mongomodel/concerns/record_status.rb
mongomodel-0.4.0 lib/mongomodel/concerns/record_status.rb
mongomodel-0.3.6 lib/mongomodel/concerns/record_status.rb
mongomodel-0.3.5 lib/mongomodel/concerns/record_status.rb
mongomodel-0.3.4 lib/mongomodel/concerns/record_status.rb
mongomodel-0.3.3 lib/mongomodel/concerns/record_status.rb