Expiremental approach for providing reloading of Grape-based rack applications in dev environment.
It uses Ripper to extract class usage and definitions from code and reloads files and API classes based on dependency map.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install grape-reload
In your config.ru you use Grape::RackBuilder to mount your apps:
Grape::RackBuilder.setup do
logger Logger.new(STDOUT)
add_source_path File.expand_path('**/*.rb', YOUR_APP_ROOT)
reload_threshold 1 # Reload sources not often one second
force_reloading true # Force reloading for any environment (not just dev), useful for testing
mount 'Your::App', to: '/'
mount 'Your::App1', to: '/app1'
end
run Grape::RackBuilder.boot!.application
Grape::Reload will resolve all class dependencies and load your files in appropriate order, so you don't need to include 'require' or 'require_relative' in your sources.
If you want to monkey-patch class in code, you want to be reloaded, for any reason, you should use
AlreadyDefined.class_eval do
end
instead of
because it confuses dependency resolver
Full-qualified const name usageConsider code
require 'some_file' # (declares SomeModule::SomeClass)
here_is_your_code(SomeClass)
Ruby will resolve SomeClass to SomeModule::SomeClass in runtime. Dependency resolver will display an error, because it expects you to use full-qualified class name in this situation. Anyway, it would not raise exception anymore (since e5b58f4)
here_is_your_code(SomeModule::SomeClass)
Avoid declaring constants as follows
class AlreadyDeclaredModule::MyClass
end
use
module AlreadyDeclaredModule
class MyClass
end
end
instead
## TODO
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4