Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Create loaders that load and validate app logic #220
As discussed, we're moving away from blindly loading everything in
App logic (e.g. mappers, models, presenters, resources, routers, and views) will all be loaded in a similar way. On boot, we'll navigate through each destination, loading each file and performing validation. The app won't boot unless validation succeeds.
How validation occurs depends on what is loaded. We want to be reasonably sure that anything we load defines valid state for the app. This will happen via a new concept called loaders. A loader will be defined for each type that specifies 1) where to find the files and 2) validation rules.
Here's what a loader for resources might look like:
module Pakyow class App load :resources, with: Loaders::Resource end module Loaders class Resource < Base location :resources def initialize(filename, resource) @filename = filename @resource = resource # warn if @resource.name does not match @filename # # we could error here, but a warning seems to make more sense # given that everything will work fine (we don't infer meaning # from the filename) but we would prefer that the naming # convention used makes good sense end def valid? # valdate that: # @resource is a Router subclass # @resource expanded the resource template end end end end