Sha256: 728d2af35eba23ea3e16f6c2ef6a96613d9b96c3516d36f7c4debfde7c20e946

Contents?: true

Size: 1.65 KB

Versions: 17

Compression:

Stored size: 1.65 KB

Contents

def delete
  update_attributes :trash => true unless new_card?
end

def delete!
  update_attributes! :trash => true unless new_card?
end


event :pull_from_trash, :before=>:store, :on=>:create do
  if trashed_card = Card.find_by_key_and_trash(key, true)
    # a. (Rails way) tried Card.where(:key=>'wagn_bot').select(:id), but it wouldn't work.  This #select
    #    generally breaks on cards. I think our initialization process screws with something
    # b. (Wagn way) we could get card directly from fetch if we add :include_trashed (eg).
    #    likely low ROI, but would be nice to have interface to retrieve cards from trash...
    self.id = trashed_card.id
    @from_trash = true
    @new_record = false
  end
  self.trash = false
  true
end

event :validate_delete, :before=>:approve, :on=>:delete do
  if !codename.blank?
    errors.add :delete, "#{name} is is a system card. (#{codename})"
  end
  
  undeletable_all_rules_tags = %w{ default style layout create read update delete }
  if junction? and l=left and l.codename == 'all' and undeletable_all_rules_tags.member? right.codename
    errors.add :delete, "#{name} is an indestructible rule"
  end
  
  if account && Card::Act.find_by_actor_id( self.id )
    errors.add :delete, "Edits have been made with #{name}'s user account.\nDeleting this card would mess up our history."
  end
end

event :validate_delete_children, :after=>:approve, :on=>:delete do
  children.each do |child|
    child.supercard = self
    subcards[child.name]=child
    child.trash = true
    unless child.valid?
      child.errors.each do |field, message|
        errors.add field, "can't delete #{child.name}: #{message}"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
card-1.16.4 mod/01_core/set/all/trash.rb
card-1.16.3 mod/01_core/set/all/trash.rb
card-1.16.2 mod/01_core/set/all/trash.rb
card-1.16.1 mod/01_core/set/all/trash.rb
card-1.16.0 mod/01_core/set/all/trash.rb
card-1.15.7 mod/01_core/set/all/trash.rb
card-1.15.6 mod/01_core/set/all/trash.rb
card-1.15.5 mod/01_core/set/all/trash.rb
card-1.15.4 mod/01_core/set/all/trash.rb
card-1.15.3 mod/01_core/set/all/trash.rb
card-1.15.2 mod/01_core/set/all/trash.rb
card-1.15.1 mod/01_core/set/all/trash.rb
card-1.15.0 mod/01_core/set/all/trash.rb
card-1.15.pre2 mod/01_core/set/all/trash.rb
card-1.15.pre mod/01_core/set/all/trash.rb
wagn-1.14.9 mod/01_core/set/all/trash.rb
wagn-1.14.8 mod/01_core/set/all/trash.rb