Skip to content

Commit

Permalink
add few locations requested for traction to the location_creator task
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrine33 committed Nov 15, 2024
1 parent b1ae715 commit 5900361
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
15 changes: 11 additions & 4 deletions app/models/location_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ def create_locations(type, location, parents)
parents.each do |parent|
if location[:number]
(1..location[:number]).each do |i|
locations << create_location("#{location[:location]} #{i}", location_type, parent, location[:container])
locations << create_location("#{location[:location]} #{i}", location_type, parent, location[:container],
location[:barcode])
end
else
locations << create_location(location[:location], location_type, parent, location[:container])
locations << create_location(location[:location], location_type, parent, location[:container],
location[:barcode])
end
end
end
end

def create_location(location, location_type, parent, container)
UnorderedLocation.find_or_create_by!(name: location, container: container) do |l|
def create_location(location, location_type, parent, container, barcode)
puts "Creating location: #{location} #{barcode}"

find_or_create_attributes = { name: location, container: container }
find_or_create_attributes[:barcode] = barcode if barcode.present?

UnorderedLocation.find_or_create_by!(find_or_create_attributes) do |l|
l.parent = parent
l.location_type = location_type
end
Expand Down
55 changes: 48 additions & 7 deletions lib/tasks/location_creator.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,53 @@ desc 'locations'
namespace :locations do
desc 'create some locations'
task create: :environment do |_t|
location_creator = LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA315', container: false },
'Freezer' => { location: 'Freezer1', container: true },
'Shelf' => { location: 'Shelf', number: 2, container: true },
'Tray' => { location: 'Tray', number: 208, container: true })
location_creator.run!
locations = [
LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA214', container: false },
'Freezer' => { location: 'Long Read DTOL Freezer 2', container: true },
'Shelf' => { location: 'Shelf 3', container: true },
'Rack' => { location: 'Rack 3', container: true },
'Tray' => { location: 'Drawer 2', barcode: 'lw-drawer-2-30398',
container: true }),

LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA309', container: false },
'Freezer -20C' => { location: 'LRT020', container: false },
'Shelf' => { location: 'SHELF 1', container: false },
'Drawer' => { location: 'Drawer 1', barcode: 'lw-drawer-1-37292',
container: true }),

LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA309', container: false },
'Upright fridge +4c' => { location: 'LRT018', container: false },
'Shelf' => { location: 'Shelf 1', barcode: 'lw-shelf-1-30503',
container: true }),

LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA309', container: false },
'Freezer -20 upright' => { location: 'LRT006', container: true },
'Shelf' => { location: 'Shelf 1', barcode: 'lw-shelf-1-30472',
container: true }),

LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA309', container: false },
'Upright fridge +4c' => { location: 'LRT007', container: true },
'Shelf' => { location: 'Shelf 1', barcode: 'lw-shelf-1-30451',
container: true }),

LocationCreator.new('Site' => { location: 'Sanger', container: false },
'Building' => { location: 'Ogilvie', container: false },
'Room' => { location: 'AA315', container: false },
'Freezer' => { location: 'Freezer1', container: true },
'Shelf' => { location: 'Shelf', number: 2, container: true },
'Tray' => { location: 'Tray', number: 208, container: true })
]

locations.each(&:run!)
end
end

0 comments on commit 5900361

Please sign in to comment.