Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/peictt
. To experiment with that code, run bin/console
for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
Installation
Add this line to your application's Gemfile:
gem 'peictt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install peictt
Usage
When creating a new Peictt application, a few things need to be setup and a few rules adhered to. Peictt follows the same folder structure as a typical rails app with all of the model, view and controller code packed inside of an app folder, configuration based code placed inside a config folder and the main database file in a db folder. Here is a link to a to-do app built using Peictt with the correct folder setup, it can be forked, cloned and edited to suit other purposes.
Generators
Peictt has generators that help to make work flow easy
New App
Generates new folder structure for the named app with the basic files needed
peictt new appname
New Controller
Creates new controller file with the name provided
peictt generate controller controllername
New Model
Creates new model file with the name provided
peictt generate model modelname
New Migration
Creates new migration file with the tablename provided
peictt generate migration tablename
Tasks
Start Server
Runs the Server
peictt server
Run Migrations
Executes the migrations
peictt migrate
Drop Tables
Deletes all Database Tables
peictt drop_tables
Reset Database
Deletes all tables in the database and creates the tables
peictt reset_db
Setup
In order to run a Peictt app, it is assumed that a config.ru
file exists in the root directory and all the needed files have been required here.
Example config.ru
file:
- Note that the 'APP_ROOT' constant is required and must point to the current file directory as the gem uses this internally to find and link folders.
require "bundler"
Bundler.require
require_all "app"
APP_ROOT = __dir__
module MyApp
class Application < Peictt::Application
end
end
peicttApp = MyApp::Application.new
require File.expand_path __FILE__, "./config/routes"
run peicttApp
Routes
The route file should be required in the config.ru file after the application has been initialized and before the rack 'run' command is called.
Example route file:
MyApp.routes.draw do
root "pages#index"
get "about", to: "pages#about"
get "contact", to: "pages#contact"
get "signup", to: "pages#signup"
post "signup", to: "users#create"
put "user/:id", to: "users#update"
delete "user/:id", to: "agendas#destroy"
match /regexp/, controller: <ControllerClass>, action: <controller_action>, methods: ["GET","POST"]
end
Models
Peictt implements a lightweight orm that makes it easy to query the database using ruby objects. It supports only sqlite3. Models are placed inside the app/models
folder.
Example model file:
class App < Peictt::BaseModel
end
Controllers
Controllers are placed inside the app/controllers
folder.
Example controller file:
class PagesController < Peictt::Controller
def index
@todos = Todo.all
end
def about
end
def show
@todo = Todo.find_by id: params[:id]
end
end
Render action
The render action can be used to modify the response from the server. Default renders "text/html"
To render json
render json: {}
So Peictt uses the method name to find the corresponding file *.json.haml
in the application views folder
To render text
render text: "This is a text"
To use another controller view file with the same method
render controller: "controller_name"
To use another controller with a different view file
render controller: "controller_name", action: "action_name"
To passing locals to the view
render locals: {name: "name"}
Views
View templates are mapped to controller actions and must assume the same nomenclature as their respective actions. Haml is used as the templating engine and files which are views are required to have the .haml
file extension. Views are placed inside the app/views
folder. A default layout file is required and must be placed inside the app/views/layouts
folder. It is also required that this file is named application.haml
and has a yield
command.
Example file:
%head
%title Todo Application
%body
= yield
Running the tests
Test files are placed inside the spec/unit folder. You can run the tests from your command line client by typing rspec spec
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/andela-tpeters/peictt. 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.