Module: ActsAsTemporary::InstanceMethods

Defined in:
lib/acts_as_temporary/acts_as_temporary.rb

Instance Method Summary collapse

Instance Method Details

#can_be_temporary?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/acts_as_temporary/acts_as_temporary.rb', line 25

def can_be_temporary?
  true
end

#drop_temporaryObject



50
51
52
53
54
55
# File 'lib/acts_as_temporary/acts_as_temporary.rb', line 50

def drop_temporary
  if @temporary_id.present?
    TemporaryObject.destroy(@temporary_id)
    @temporary_id = nil
  end
end

#is_temporary?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/acts_as_temporary/acts_as_temporary.rb', line 46

def is_temporary?
  @temporary_id.present?
end

#recall(temp_id = nil) ⇒ Object



41
42
43
44
# File 'lib/acts_as_temporary/acts_as_temporary.rb', line 41

def recall(temp_id=nil)
  temp_id ||= @temporary_id
  self.class.send(:recall, temp_id)
end

#shelf_lifeObject



29
30
31
# File 'lib/acts_as_temporary/acts_as_temporary.rb', line 29

def shelf_life
  Rails.application.config.acts_as_temporary_shelf_life
end

#storeObject



33
34
35
36
37
38
39
# File 'lib/acts_as_temporary/acts_as_temporary.rb', line 33

def store
  temporary_object = TemporaryObject.new
  temporary_object.permanent_class = self.class.name
  temporary_object.definition = self.attributes
  temporary_object.save
  @temporary_id = temporary_object.id
end