I have hanami 1.3.0 app named booking
. There is rake task in /rakelib/motel.rake
:
require_relative '../lib/booking' # it requires booking/motel/booker file
namespace :motel do
task :book do
Booking::Motel::Booker.new.book
end
end
booking/motel/booker
requires booking_repository file, and tries to instantiate BookingRepository, but fails with error:
NameError: uninitialized constant Hanami::Repository
<root>/lib/booking/repositories/booking_repository.rb:1:in <top (required)>'
However, when I run Booking::Motel::Booker.new.book
in hanami console, it loads BookingRepository
without problems.
Looked at numerous stack questions regarding hanami rake, but couldn't find an answer.
As it turns out, it was a foolish mistake. I forgot to add :environment
to my task.
namespace :motel do
task book: :environment do
Booking::Motel::Booker.new.book
end
end
That fixed it and dropped the need to use manual file loading, of course.