2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2007-10-26 01:56:46 -04:00
|
|
|
class Parrot < ActiveRecord::Base
|
2011-11-29 10:34:22 -05:00
|
|
|
self.inheritance_column = :parrot_sti_class
|
|
|
|
|
2007-10-26 01:56:46 -04:00
|
|
|
has_and_belongs_to_many :pirates
|
|
|
|
has_and_belongs_to_many :treasures
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :loots, as: :looter
|
2008-08-15 21:49:22 -04:00
|
|
|
alias_attribute :title, :name
|
2009-01-31 20:44:30 -05:00
|
|
|
|
|
|
|
validates_presence_of :name
|
2010-01-08 14:47:49 -05:00
|
|
|
|
2017-07-18 10:37:31 -04:00
|
|
|
attribute :cancel_save_from_callback
|
2016-08-06 13:37:57 -04:00
|
|
|
before_save :cancel_save_callback_method, if: :cancel_save_from_callback
|
2010-01-08 14:47:49 -05:00
|
|
|
def cancel_save_callback_method
|
2014-12-15 01:10:15 -05:00
|
|
|
throw(:abort)
|
2010-01-08 14:47:49 -05:00
|
|
|
end
|
2016-12-29 02:17:01 -05:00
|
|
|
|
|
|
|
before_update :increment_updated_count
|
|
|
|
def increment_updated_count
|
|
|
|
self.updated_count += 1
|
|
|
|
end
|
2018-10-29 21:53:59 -04:00
|
|
|
|
|
|
|
def self.delete_all(*)
|
|
|
|
connection.delete("DELETE FROM parrots_pirates")
|
|
|
|
connection.delete("DELETE FROM parrots_treasures")
|
|
|
|
super
|
|
|
|
end
|
2007-10-26 01:56:46 -04:00
|
|
|
end
|
2007-11-26 17:46:11 -05:00
|
|
|
|
|
|
|
class LiveParrot < Parrot
|
|
|
|
end
|
|
|
|
|
|
|
|
class DeadParrot < Parrot
|
2016-08-06 13:37:57 -04:00
|
|
|
belongs_to :killer, class_name: "Pirate", foreign_key: :killer_id
|
2007-11-26 17:46:11 -05:00
|
|
|
end
|