mirror of
https://github.com/lazuscripts/locator.git
synced 2024-11-19 10:54:24 +00:00
minor fixes to locator
This commit is contained in:
parent
a819ae4331
commit
e7a5b47f9f
31
init.moon
31
init.moon
@ -3,21 +3,21 @@ config = require "locator_config"
|
|||||||
import insert, sort from table
|
import insert, sort from table
|
||||||
|
|
||||||
-- locates and returns a module, or errors
|
-- locates and returns a module, or errors
|
||||||
-- if priority (path) specified, will check it before other paths
|
-- if a path is specified, it will be checked before other paths
|
||||||
-- checks project root first, then each path specified in locator_config
|
-- checks the project root, then each path specified in locator_config
|
||||||
try_require = (path, priority) ->
|
try_require = (name, path) ->
|
||||||
if priority
|
if path
|
||||||
ok, value = pcall -> require "#{priority}.#{path}"
|
ok, value = pcall -> require "#{path}.#{name}"
|
||||||
return value if ok
|
return value if ok
|
||||||
|
|
||||||
ok, value = pcall -> require path
|
ok, value = pcall -> require name
|
||||||
return value if ok
|
return value if ok
|
||||||
|
|
||||||
for item in *config
|
for item in *config
|
||||||
ok, value = pcall -> require "#{item.path}.#{path}"
|
ok, value = pcall -> require "#{item.path}.#{name}"
|
||||||
return value if ok
|
return value if ok
|
||||||
|
|
||||||
error "locator could not find '#{path}'"
|
error "locator could not find '#{name}'"
|
||||||
|
|
||||||
-- works like Lapis's autoload, but
|
-- works like Lapis's autoload, but
|
||||||
-- includes trying sub-application paths & can be called to access a value
|
-- includes trying sub-application paths & can be called to access a value
|
||||||
@ -55,15 +55,16 @@ make_migrations = (app_migrations={}) ->
|
|||||||
|
|
||||||
return app_migrations
|
return app_migrations
|
||||||
|
|
||||||
-- return access to autoload and migrations functions,
|
-- return access to autoload and make_migrations functions,
|
||||||
-- and metamethods for getting autoloaders
|
-- a self-reference, and metamethods for getting autoloaders
|
||||||
return setmetatable {
|
locator = {
|
||||||
:autoload, :make_migrations
|
locate: locator, :autoload, :make_migrations
|
||||||
}, {
|
}
|
||||||
__call: (t, here) ->
|
return setmetatable locator, {
|
||||||
|
__call: (t, here="") ->
|
||||||
if "init" == here\sub -4
|
if "init" == here\sub -4
|
||||||
here = here\sub 1, -6
|
here = here\sub 1, -6
|
||||||
unless here
|
unless here\len! > 0
|
||||||
here = ""
|
here = ""
|
||||||
return autoload here
|
return autoload here
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user