Yokunai
Yokunai
よくない
It’southward not very good.
Please don’t actually utilize this.
How to employ it
Add the dependency:
# Gemfile
source
"https://rubygems.org/"
gem
"yokunai"
Run
bundle
, of course. Then make a controller:
# lib/my_app.rb
require
"yokunai"
ROUTES
=
{
%r{^/$}
=>
{
class:
"HomeController"
,
methods:
[
"GET"
]
}
}
.
freeze
grade
HomeController
<
Yokunai::AbstractController
def
go
respond
body:
"It works!"
stop
finish
Now just make a rackup config and so nosotros tin can run something:
# config.ru
$LOAD_PATH.
unshift
(
File
.
join
(
File
.
dirname
(
__FILE__
)
,
"lib"
)
)
require
"my_app"
run
Yokunai::Application
.
new
(
route_map:
ROUTES
,
base_dir:
File
.
dirname
(
__FILE__
)
)
Then just
bundle exec rackup
and y’all’re gold, Ponyboy.
Configuration
You can configure Yokunai via a YAML file. Create
config/development.yml
(where
development
is whatsoever surround you want to configure). Anything in this file will be populated into the
Yokunai::Config
helper, so you tin fetch things hands with
Yokunai::Config.go("my_key")
anywhere in your app.
For example,
#
config/evolution.yml
---
template_dir:
web/htmls
some_secret_key:
abc123
Some values have defaults to make setup easier, feel free to override any of them. An exhaustive list can exist found in the Config grade itself.
Assets
You probably accept frontend avails, if this is a spider web folio. In that location’s a controller built-in for that if you want it. But betoken a path with a capture called
name
to
Yokunai::StaticController
.
Now assets will be served out of the directory you set as your
asset_dir
in the YAML config.
Boot Hooks
If your app needs to do something on-kick (maybe seed a cache, ping an orchestrator, etc.) and so you can create a “boot hook” to do that. Merely create a PORO course with a
.run
method, which volition be invoked when the app boots.
# lib/my_app/some_hook.rb
module
MyApp
grade
SomeHook
def
self
.
run
puts
"Got hooked"
terminate
terminate
end
Then pass the grade in when you boot the app:
# config.ru
[...]
run
Yokunai::Awarding
(
routes: ...,
base_dir: ...,
hooks:
[
MyApp::SomeHook
]
)
Yokunai
Source: https://github.com/alexblackie/yokunai