Skip to content

vergilet/fasta

Repository files navigation

Fasta

Just a mini web framework

Installation

 $ gem install fasta
 $ fasta plz NEW_APP_NAME
 $ cd NEW_APP_NAME

Start

Before first start run

 $ rake db:create

To start server:

 $ fasta go [-e ENVIRONMENT] [-p PORT]

or advanced

 $ puma boot.ru -e production -p 3210

Add Endpoint

 $ fasta endpoint <ENDPOINT_NAME> <ACTION> <ACTION> <ACTION> ... 
 # fasta endpoint account index show custom

After generate endpoint add the appropriate routes in routes.rb and extend a migration with needed fields:

 # routes.rb

 $router = Fasta::Router.new do |mapper|
   ...
   mapper.reg(:<METHOD>, '/<PATH>', <ENDPOINT>::<ACTION>)  
   
 # mapper.reg(:get, '/accounts', Account::Index)
   ...
 end  

Also after set up migration file run:

 $ rake db:migrate

Associated Entities

    # app/endpoints/user/boards.rb

    module User
      class Boards < Model::Show
        validate_fields :id
        
        def fetch
          user_id = params[:id]
          through = DB[:users_boards].where(user_id: user_id)
          DB[:boards].where(id: through.select(:board_id)).to_a
        end
      end
    end
    # routes.rb
    $router = Fasta::Router.new do |mapper|
      ...
      mapper.reg(:get, '/users/:id/boards', User::Boards) 
      ...
    end

Namespaces

    # app/endpoints/team/user.rb
    
    module Team
      module User
        extend Model
      end
    end
 
    # app/endpoints/team/user/index.rb
    
    module Team
      module User
        class Index < Model::Index; end
      end
    end 
    # routes.rb
    $router = Fasta::Router.new do |mapper|
      ...
      mapper.reg(:get, 'team/users', Team::User::Index)
      ...
    end  

Usage

TODO:

  1. Write usage instructions here
  2. Show and Index considering