1
0
Fork 0
forked from OpenNeo/impress

Fix old find_or_initialize_by methods

I missed this in the Rails upgrades, oops!
This commit is contained in:
Emi Matchu 2023-10-12 18:05:01 -07:00
parent f21a7da362
commit 1e690d9f6c
3 changed files with 10 additions and 10 deletions

View file

@ -50,7 +50,7 @@ class NeopetsUser
pets_data = envelope.messages[0].data.body pets_data = envelope.messages[0].data.body
raise NotFound if pets_data == false raise NotFound if pets_data == false
pets = pets_data.map { |pet| Pet.find_or_initialize_by_name(pet['name']) } pets = pets_data.map { |pet| Pet.find_or_initialize_by(name: pet['name']) }
items = pets.each(&:load!).map(&:items).flatten items = pets.each(&:load!).map(&:items).flatten
item_ids = items.map(&:id) item_ids = items.map(&:id)
item_quantities = {} item_quantities = {}

View file

@ -31,9 +31,9 @@ class Pet < ApplicationRecord
pet_data = viewer_data[:custom_pet] pet_data = viewer_data[:custom_pet]
self.pet_type = PetType.find_or_initialize_by_species_id_and_color_id( self.pet_type = PetType.find_or_initialize_by(
pet_data[:species_id].to_i, species_id: pet_data[:species_id].to_i,
pet_data[:color_id].to_i color_id: pet_data[:color_id].to_i
) )
self.pet_type.body_id = pet_data[:body_id] self.pet_type.body_id = pet_data[:body_id]
self.pet_type.origin_pet = self self.pet_type.origin_pet = self
@ -166,13 +166,13 @@ class Pet < ApplicationRecord
end end
def self.load(name, options={}) def self.load(name, options={})
pet = Pet.find_or_initialize_by_name(name) pet = Pet.find_or_initialize_by(name: name)
pet.load!(options) pet.load!(options)
pet pet
end end
def self.from_viewer_data(viewer_data, options={}) def self.from_viewer_data(viewer_data, options={})
pet = Pet.find_or_initialize_by_name(viewer_data[:custom_pet][:name]) pet = Pet.find_or_initialize_by(name: viewer_data[:custom_pet][:name])
pet.use_viewer_data(viewer_data, options) pet.use_viewer_data(viewer_data, options)
pet pet
end end

View file

@ -162,10 +162,10 @@ class PetState < ApplicationRecord
if pet_type.new_record? if pet_type.new_record?
pet_state = self.new :swf_asset_ids => swf_asset_ids_str pet_state = self.new :swf_asset_ids => swf_asset_ids_str
else else
pet_state = self.find_or_initialize_by_pet_type_id_and_swf_asset_ids( pet_state = self.find_or_initialize_by(
pet_type.id, pet_type_id: pet_type.id,
swf_asset_ids_str swf_asset_ids: swf_asset_ids_str
) )
end end
existing_swf_assets = SwfAsset.biology_assets.includes(:zone). existing_swf_assets = SwfAsset.biology_assets.includes(:zone).
find_all_by_remote_id(swf_asset_ids) find_all_by_remote_id(swf_asset_ids)