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
@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
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
@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
Paleidimas yra analogiškas: console [project_name].
Ir, galiausiai, dažnai tenka pasinaudoti projekto generatoriais arba migration’ais. Tam skirtas project.bat
@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
Dirbti tokioje aplinkoje (ypač jei dirbama su daug projektu) ir efektyvu ir malonu.
keista kodėl neparašei šio skripto su ruby? .)
Paprastumas ir laiko stoka. Ateityje (jei atsiras laiko) neatmetu galimybės sujungti visas šias “konsoles” į vieną ruby script’ą.