Module: Transient::ActiveRecordExtensions::SingleActive

Defined in:
lib/transient/active_record_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/transient/active_record_extensions.rb', line 139

def self.included( base ) #:nodoc:
  base.before_create :expire_current_active

  private

  def expire_current_active
    #if self.transient_options[:check_exists]
    #  exists_conditions = {}
    #  self.transient_options[:check_exists].each { |attr| exists_conditions.merge!( attr.to_sym => attributes[attr] ) }
    #  #cur = self.class.current.find( :first, :conditions => exists_conditions )
    #  return true if self.class.current.exists?( exists_conditions )
    #end

    conditions = {}
    self.transient_options[:single_active].each { |attr| conditions.merge!( attr.to_sym => attributes[attr] ) }
    old = self.class.effective.first( :conditions => conditions )
    old.expire! unless old.nil?
  end
end

Instance Method Details

#expire_current_activeObject



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/transient/active_record_extensions.rb', line 144

def expire_current_active
  #if self.transient_options[:check_exists]
  #  exists_conditions = {}
  #  self.transient_options[:check_exists].each { |attr| exists_conditions.merge!( attr.to_sym => attributes[attr] ) }
  #  #cur = self.class.current.find( :first, :conditions => exists_conditions )
  #  return true if self.class.current.exists?( exists_conditions )
  #end

  conditions = {}
  self.transient_options[:single_active].each { |attr| conditions.merge!( attr.to_sym => attributes[attr] ) }
  old = self.class.effective.first( :conditions => conditions )
  old.expire! unless old.nil?
end