Sha256: 8673898db5757b483a8f2fb93cff5f012a47e7c8ce06655d45fae773dba2f186

Contents?: true

Size: 776 Bytes

Versions: 13

Compression:

Stored size: 776 Bytes

Contents

def cards_of_type_exist?
  !new_card? && Card.where(trash: false, type_id: id).exists?
end

def create_ok?
  Card.new(type_id: id).ok? :create
end

def was_cardtype?
  type_id_before_act == Card::CardtypeID
end

event :check_for_cards_of_type, after: :validate_delete do
  errors.add :cardtype, t(:core_cards_exist, cardname: name) if cards_of_type_exist?
end

event :check_for_cards_of_type_when_type_changed,
      :validate, changing: :type, when: :was_cardtype? do
  if cards_of_type_exist?
    errors.add :cardtype, t(:core_error_cant_alter, name: name_before_act)
  end
end

event :validate_cardtype_name, :validate, on: :save, changed: :name do
  if %r{[<>/]}.match?(name)
    errors.add :name, t(:core_error_invalid_character_in_cardtype, banned: "<, >, /")
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
card-1.104.2 mod/core/set/type/cardtype.rb
card-1.104.1 mod/core/set/type/cardtype.rb
card-1.104.0 mod/core/set/type/cardtype.rb
card-1.103.4 mod/core/set/type/cardtype.rb
card-1.103.3 mod/core/set/type/cardtype.rb
card-1.103.2 mod/core/set/type/cardtype.rb
card-1.103.1 mod/core/set/type/cardtype.rb
card-1.103.0 mod/core/set/type/cardtype.rb
card-1.101.7 mod/core/set/type/cardtype.rb
card-1.102.0 mod/core/set/type/cardtype.rb
card-1.101.6 mod/core/set/type/cardtype.rb
card-1.101.5 mod/core/set/type/cardtype.rb
card-1.101.4 mod/core/set/type/cardtype.rb