Skip to content

Habu-Kagumba/rapid_runty

Repository files navigation

Rapid Runty

Rapid Runty

Gem Version Dependency Status Codeship Status for Habu-Kagumba/rapid_runty Coverage Status codebeat badge Inline docs

Rapid Runty is a minimal web framework to get your web project up and running in seconds.

Dependencies

  1. Ruby
  2. SQlite3
  3. Bundler
  4. Rack
  5. Rspec

Installation

Add this line to your application's Gemfile:

gem 'rapid_runty'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rapid_runty

Usage

You application structure should be as follows:

.
├── Gemfile
├── app
│   ├── controllers
│   ├── models
│   └── views
│       └── layouts
│           └── application.html.haml
├── config
│   ├── application.rb
│   └── routes.rb
├── config.ru
└── db

Hacking

Start by defining an Application class that inherits from RapidRunty::Application.

require 'rapid_runty'

$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'controllers')
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'models')

module TodoList
  class TodoApplication < RapidRunty::Application
  end
end

Configuration

You need to define the ROOT_DIR in the config.ru file. e.g.

require_relative './config/application'
ROOT_DIR = __dir__

use Rack::MethodOverride # masks put and delete methods requests as post requests

run TodoListApplication

Routes

Define your application routes.

TodoApplication.routes.draw do
  root "todo#index"
  get "/todo", to: "todo#index"
  get "/todo/new", to: "todo#new"
  get "/todo/:id", to: "todo#show"
  get "/todo/:id/edit", to: "todo#edit"
  post "/todo", to: "todo#create"
  put "/todo/:id", to: "todo#update"
  delete "/todo/:id", to: "todo#destroy"
end

Add the route file to the config file

[...]
require_relative './config/routes'
[...]

Models

Define your models in the app/models directory.

class Todo < RapidRunty::Model::Base
  to_table :todos
  property :id, type: :integer, primary_key: true
  property :title, type: :text, nullable: false
  property :body, type: :text, nullable: false
  property :created_at, type: :text, nullable: false
  create_table
end

Controllers

Defines your controllers in the app/controllers directory.

class TodosController < RapidRunty::BaseController
  def index
    @todos = Todo.all
  end

  def show
    @todo = Todo.find(params['id'])
  end

  def new
  end

  def create
    todo = Todo.new
    todo.title = params['title']
    todo.body = params['body']
    todo.created_at = Time.now.to_s
    todo.save

    redirect_to '/todos'
  end

  def edit
    @todo = Todo.find(params['id'])
  end

  def update
    todo = Todo.find(params['id'])
    todo.title = params['title']
    todo.body = params['body']
    todo.save

    redirect_to "/todos/#{todo.id}"
  end

  def destroy
    todo = Todo.find(params['id'])
    todo.destroy

    redirect_to '/todos'
  end
end

Views

This are the last piece to make the framework work.

You need to define the layout file located at app/views/layouts/application.html.haml.

!!!
%html{:lang => 'en'}
  %head
    %meta{:content => 'text/html; charset=UTF-8', 'http-equiv' => 'Content-Type'}/
    %meta{:charset => 'UTF-8'}/
    %title Todo Application
  %body
    = yield

Running the application

To run the application, run from you the root of your application,

$ rackup

Tests

To run the tests, run this command from the root of your application,

$ rspec -fd

Limitations

  • TODO - Generate application files with rake command.
  • TODO - Support model relationships.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Habu-Kagumba/rapid_runty. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

About

A minimal web framework to get web project up and running in seconds.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published