When ‘auto-import’ components, one should carefully read the Documentation here.
The paragraph that say
lib/api/client
resolves toAPI::Client
class with identifier ‘api.client’.
Could be better illustrated with a folder structure that show a
#{root}
|- lib
|- api
client.rb
and client.rb
Module Api
class Client
...
end
end
Also it seems to me that on the last code of the lib/persistence/user_repo.rb
the class should be in the persistence
module.
as
# lib/persistence/user_repo.rb
require 'import'
module Persistence
class UserRepo
include Import['persistence.db']
def find(conditions)
db[:users].where(conditions)
end
end
end
as if someone would like to use it from somewhere else, it would be registered as persistence.user_repo
but when instantiating the component.instance
it won’t find the proper Persistent::UserRepo
constant defined.
I struggled a long moment, before finding why an ‘auto-import’ class, was reporting something like ‘constant Api not foundfor a component in a
/lib/api/client.rb’ under key 'api.client'
until I wrapped the Client
class into the proper Api
module as the directory structure dictate it.
Or the loader
should try harder