Greita prieiga prie Rails projektų

Viena iš pagrindinių, o gal ir pagrindinė priežastis, kodėl prieš kelis metus pasirinkau Ruby on Rails yra produktyvumas ir paprastumas. Ir jeigu pačiame Rails’e jų pakanka, tai dirbant su keliais projektais vienu metu (that’s life =)) pastebėjau, kad menko pakeitimo padarymas (o veikiau pasiruošimas tam padarymui) užima labai daug laiko. Susimasčiau ar nieko su tuo negalima padaryti – pasirodo galimą, ir atsakymas yra ganėtinai paprastas: batch files =D.

Reikia sukurti bylą server.bat su šiuo turiniu

[code]

@echo off
rem Launches server for specified Ruby on Rails project
rem Usage: server [project_name]

set projects_path=d:work
set project_name=%1
set port=80

if not exist %projects_path%. goto wrong_projects_path
if not exist %projects_path%%project_name%. goto wrong_project_name
chdir /d %projects_path%%project_name%
ruby %projects_path%%project_name%scriptserver -p %port%
goto end

:wrong_projects_path
echo Wrong projects path. Check projects_path variable in this batch file
pause
goto end

:wrong_project_name
echo Wrong project name. Please specify the directory for you Ruby on Rails application
pause
goto end

:end

[/code]

ir išsaugoti kur nors, kur windows’as galėtu ją pasiekti (pvz. windows direktorijoje). Tada projekto paleidimas atrodo taip: paspaudžiame Win+R (t.y. Start -> Run) ir įrašome server [project_name] (akivaizdu, jog project_name yra projekto pavadinimas).

Kitas dalykas, kurio dažnai prireikia yra konsolės paleidimas tam tikram projektui. Vėlgi sukuriame analogišką batch bylą pavadintą console.bat

[code]

@echo off
rem Launches console for specified Ruby on Rails project
rem Usage: console [project_name]

set projects_path=d:work
set project_name=%1
set port=80

if not exist %projects_path%. goto wrong_projects_path
if not exist %projects_path%%project_name%. goto wrong_project_name
chdir /d %projects_path%%project_name%
ruby %projects_path%%project_name%scriptconsole
goto end

:wrong_projects_path
echo Wrong projects path. Check projects_path variable in this batch file
pause
goto end

:wrong_project_name
echo Wrong project name. Please specify the directory for you Ruby on Rails application
pause
goto end

:end

[/code]

Paleidimas yra analogiškas: console [project_name].

Ir, galiausiai, dažnai tenka pasinaudoti projekto generatoriais arba migration’ais. Tam skirtas project.bat

[code]

@echo off
rem Launches console for specified Ruby on Rails project
rem Usage: console [project_name]

set projects_path=d:work
set project_name=%1
set port=80

if not exist %projects_path%. goto wrong_projects_path
if not exist %projects_path%%project_name%. goto wrong_project_name
chdir /d %projects_path%%project_name%
start cmd.exe
goto end

:wrong_projects_path
echo Wrong projects path. Check projects_path variable in this batch file
pause
goto end

:wrong_project_name
echo Wrong project name. Please specify the directory for you Ruby on Rails application
pause
goto end

:end

[/code]

Dirbti tokioje aplinkoje (ypač jei dirbama su daug projektu) ir efektyvu ir malonu.

3 Replies to “Greita prieiga prie Rails projektų”

  1. Paprastumas ir laiko stoka. Ateityje (jei atsiras laiko) neatmetu galimybės sujungti visas šias “konsoles” į vieną ruby script’ą.

Leave a Reply to admin Cancel reply

Your email address will not be published. Required fields are marked *