MiniRails - Ruby on MiniRails.
It's my sabbatical project. After catching burnout I chose to take long vacation. Once I watched Maple Ong's talk Building a Ruby web app using the Ruby Standard Library on Euruko 2021. The talk inspired me.
Firstly I wrote the script, the code is here. Then I started to improve it and decided to write an MVC-framework like RubyOnRails on plain Ruby. Such a good challenge. There is an article on dev.to in which I've described the process how I wrote the library and some features.
Current repo is a mono repository with source code. Folder mini_rails contains MVC-framework source code. Code in todo_list and secret_app folders are examples of application using the MiniRails library.
The project isn't written on plain Ruby. It uses rack
because rack is a standard web server interface for Ruby. Also it has dependency on puma
, and rack-test
for testing.
Features of MiniRails
- Rack-server to handle requests.
- MiniActionController - the module for controller layer in MVC pattern. It supports:
before_action
callback,params
-object, setting layout for views,rescue_from
rescue handle andredirect_to
. - MiniActionDispatch - namespace for rack middlewares. Middlewares are:
AssetHandler
- middleware to distribute stylesheets and javascript files from theassets
folder.StaticHandler
- middleware to distribute any files frompublic
folder.RequestHandler
- main middleware to receive rack-request and build response. It supports get/post/delete/put/patch requests.
- MiniActionParams - A class to parse http-headers and store params. Similar to
ActionController::Parameters
- MiniActionView - the module for view layer in MVC pattern. The layer is separated from
MiniActionController
module. Features:- HTML and JSON responses.
- HTML.ERB views rendering.
- Partial views and layout rendering.
- CSS and JS assets rendering.
- View caching.
- MiniActiveRecord - the module for model layer in MVC pattern.
List of features:
- Attribute definition in a model
has_many
andbelongs_to
associations- Base abstract driver class for implemening data manipulation for different DBs.
- Single file storage - yaml_driver
- CRUD operations for data manipulation
- Proxy object for quering with chain methods.
- Scope definition on a model class
- Data serialisation to JSON
- Validations
validates_presence_of
andvalidates_length_of
- MiniActiveRouter - the module to draw routes map and match route. Features: placeholders for params, not found route for 404 page.
- MiniActiveSupport - a bunch of extensions for different classes. It's similar to
ActiveSupport
- MiniCodeLoader - class for code-reloading. It helps when you are working with CLI console.
- CLI - with CLI you can run web-server, console, tests, runner and create a new application.
- MiniRspec - it's
RSpec
from scratch. It supports RSpec's basic structure:describe
,context
,it
. Also has callbackbefore_each
and functionlet!
to define a helper methods. You can write unit and request tests. - MiniFactory - it's a little copy of
FactoryBot
. Features: factory definition,sequence
andtrait
. - Yard documentation
There are two applications to present how the framework works: TODO list and Secret app.
You can see the application in todo_list folder
You can see the application in secret_app folder
# Clone the project
git clone [email protected]:kopylovvlad/mini_rails.git
# Install dependencies
cd mini_rails
bundle install
# Return back
cd ../
# Switch to application folder
cd todo_list
# Install dependencies
bundle install
# Run the server
./bin/mini_rails server
# Open http://0.0.0.0:9292 in a browser
# Run the console
./bin/mini_rails console
# Run the tests
./bin/mini_rails test
# Create new app
./mini_rails/bin/mini_rails new <NEW_APP_NAME>
# Done! Your application in <NEW_APP_NAME> folder
# Switch to folder
cd <NEW_APP_NAME>
bundle install
# Run the server
./bin/mini_rails server
# Open http://0.0.0.0:9292 in a browser
# You can write your own application