Greita prieiga prie Rails projektų (2 dalis)

Neatsiejamas įrankis kiekvienos Rails aplikacijos kūrime – log bylos. *nix’e viskas paprasta: tail -f log/development.log ir turime gražią išklotinę. Nors Windows’ams paprasto analogo nėra, tačiau yra galimybė susiinstaliuoti *nix’o emuliatorių – Cygwin. Kaip tik jame ir galime rasti emuliuojamą tail programėlę.

Grįžtant prie “greitos prieigos” batch byla atrodytu taip:

[code]

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

set cygwin_path=c:\cygwin\

rem Windows style path
set projects_path=d:\work\
rem Unix style path
set projects_path_for_cygwin=d/work/

set project_name=%1

if not exist %cygwin_path%. goto wrong_cygwin_path
if not exist %projects_path%. goto wrong_projects_path
if not exist %projects_path%%project_name%. goto wrong_project_name
%cygwin_path%\bin\bash –login -c “tail -f /cygdrive/%projects_path_for_cygwin%%project_name%/log/development.log”
goto end

:wrong_cygwin_path
echo Wrong cygwin path. Check cygwin_path variable in this batch file
pause
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]

o paleidimas kaip ir ankščiau Win+R bei tail [project_name].

Produktyvaus naudojimo =)

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.