Basic Rake by Jim Weirich

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'll go ahead and introduce myself while we're waiting since since this is not really pertinent information you it's okay I start early what people wandered him my name's Jim Wyrick I'm with edge case I am the chief scientist at edge case now you may be aware that that case was just purchased this year by digital rocker forming a new company called new contacts in that case is one of the companies in the new context grouping of companies and my new boss Mike Mike the boss of my boss is here real topics that I got to talk to him and we're discussing titles I said do I get a new title under the new regime he says oh yes what would you like I decided that rather than chief scientist I would like to go as chief mad scientist and he felt that was too much of a bump up so we're deciding to go as cold mats like the sheriff position with someone else but the position hasn't been filled yet sorry both jobs right now so I was Ash case I'm here to talk about rape we call this basic way from I submitted a proposal but I realize that that's so much information to give you is more like a boot camp type thing so rather basic drink go the whole basic training boot camp thing and I'm gonna just tell you a little bit about Rick and the reason I want to do this is that I've been looking a lot of Rick files that people have been doing can my gosh it is using break entirely wrong it's the whole you're doing it wrong things so I'm not here to correct all that how many people here but your rails developers right so you use break down a little bit up to maybe some luck yeah rape DB minor it might be the extent of what you do with it that's okay yeah I'm here to tell you how to take advantage of rape and users are going to give it's just some of these basic stuff about rape and how it works and and how you can use rate to improve your life so rate is a tool for organizing tasks tests are things that you need to have done so I'm going to start with kind of an overall what kind of an important task right so I'm hungry let's make some mac and cheese okay so what do I have to do to make myself some some macaroni cheese well first I've got to have some some pasta available I have to have some cheese available and I got a boil the water to make it so these are some of the subtasks that might be involved in and put it together mac and cheese meal now there are dependencies here in order to make mac and cheese that depends upon all these of a 10 so this is the essence of rate is take a task and break it down to its component pieces and specify what needs to be done in order to do the bigger task that you're trying to involve so so if you took this and run it out right rate filing who look exactly like this would specify I have my main task here mac and cheese and every task gets a title this is just Ruby code it's in a rate five got our meatball but it is just Ruby code so anything you can do in Ruby you can do in a rate file so our task names happen to be symbols that could also be strings or it doesn't care and so every task has a name every task has an action that action is encoded was a do end block that gets executed to perform that task and then finally tasks have dependencies and we specify dependencies with just strange kind of arrow syntax you say well that looks really weird but if you think about that's just hash syntax where it kind of uses a syntax quirk of Ruby in that did you give it a hash that's just an argument that gets passed into the task method and so we pull out a part to take the keys that with the task name and the list that's the value in the hash pair there that's just the list of dependencies so it's just a syntax check that Rick uses so you just left off the things that you want to have done before I could make mac and cheese I must boil the water by the cheese and by the pasta all those three things must be done so the command line we say rake mac and cheese and that is the name of that very first task like there rape mac and cheese and we see coming out of the screen boiling water bypass the buy cheese and then making the mac and cheese anybody see a problem with this I've you know I started by water boiling and then they run out to the store and I buy buy my cheese in my pasta then I come back pretty good cuz it's probably boiling by that might have bought a little probably but probably don't want to start the boiling water first so if we want their dependencies what we see is that we've missed some dependencies and what we really want to say is that before I boil the water I want to make sure I have on hand both the cheese in the past all the ingredients that go into making that so I want to specify these dependencies as well so I need to go back into my rake file and add these dependencies to the boiling water now once I've done that I've not changed anything else here in this red pile but once I've done that I get magically buying the pasta by the cheese bought in the water and making the mac and cheese to get all like dependency right dependencies right reaches automatically does the right thing I realized I never started my timer and it's really cool timer on my phone that tells me how long I've got to talk and so now you guys I'm going to go over because of this because my time is that they got an extra five minutes now on the baking path making mac and cheese okay so getting the dependencies right is important in rate so check declare all the dependencies if something must be done before any other task make them explicit dependency and just declare and then raping the magic but make sure things get done in the right order now I do want to point out that each of these things are individual cast and although I say rick mac and cheese i could have very well have said rape by cheese and when it would have done just that task so you can invoke individual tasks or you could invoke the big task that depends upon everything either way will work okay sup nice dick about us I realized that I probably broke this down a little bit incorrectly maybe I should have another task in there called go to the store because in order to buy the cheese and buy the possible actually have to go somewhere and maybe I need to have some work done this cognitive both buying cheese and buying pasta so let's add that is another task and now there's dependencies between buy cheese and buy pasta and go to the store so I'm there where I think buy the cheese now we run this oh well here's here's the big task so we have go to the store here so here's a new cast down here her list and then we also add two dependencies - cheese and pasta so then it depends upon whether the source of going to the store will be done first before either of these passes to run so I run it I magically get the right thing going to the start by the pasta by the cheese one of the water making the master cheaper think about that didn't I have I have two dependencies of good at the store why didn't I go to the store twice let's work through how great handles dependencies so I specified mac and cheese is my first dependency so great whoops at that passed and says oh well coming to make mac and cheese I see there are three dependencies on that achieves I must satisfy all the tendencies first before I can make the mac and cheese so close often starts looking down the list of dependencies and starts with the first one which happens to be boiled water and it says oh I need to borrow the boil water has two dependencies I need to look at each of this dependencies and make sure they are satisfied first and the first one is by pasta this is a look and you see a pattern here we must go to the store first as a prerequisite so let's focus on that past and this is okay go to store has requisites I can actually do the go to the store work right now because there are no dependencies that needs to have this wine so we put check that one off for us we have gone in the store we do we execute the body associated looks good in the store tasks then we go back and run back now my pasta all this dependencies have been satisfied so we can click that one off our list we go back up to chain is a big boil water it has to depend sees one of which has been done the other one still needs to be executed so it will go and focus on buy cheese it sees buy cheese has it pendency go to store but look we've already done to go to store task doesn't need to be done again rape is smart enough that once you do it fast it won't try to do it again so you won't get that repeat it's not like these things are methods and you have call and you're calling out to other methods if these were methods you go to the store twice but then rate because I just listed as dependencies that must be satisfied great news it's already satisfied and won't run it again so we put off by cheese now boiling water is done both of his dependencies are satisfied and now we're back up at make mac and cheese it has three dependencies but no look the buy cheese in my toss stuff once have already been done so there's no need to do them again and now we can click off make mac and cheese so the body for that one it's run so rate is simply turns out that the engine that drives rate is about 100 lines of code probably awesome and we do our 50 lines of code it just walks the tree of dependencies execute the prerequisites and then walks back up and it kind of depth first manner actually pretty simple coding question so far okay that's ever done actually this is the basics this is the essence of rate getting those dependencies right and declaring them right and so so what more is in Drake couple things it's really convenient just to say break at the very top level to say rate and have something do something by default so rate recognizes a past name default and if you give it dependencies it will try to satisfy them if you do nothing else so if you same rate with no caste on the command line it will go to the default path and satisfy its dependency so this is a nice way of specifying rate of the tax circularity so we'll say oh this is a sick of our dependency and will complain and groan at you until you exit I think it does so remember Dobbs it doesn't actually happen that often real life but you can occasionally get up and I'm trying to remember for complains right away or it actually tries to execute it will okay so rape is a task execution engine so let's talk about the environment in which it runs you probably have a project directory that might look something like this the top level of your project you're going to have a rate file and this is required this is where you put all your tasks and rate will recognize that name file and use that however you don't have to put every cent in there if you want to break up your rib file into component pieces there's a couple things you do number one you trade a director called rate line and put individual files in there with an extension dot rate and R it will automatically go into that directory and pull in those files as if they were part of the main rate file in addition if you are running a rails project rails tells rate to look for additional tasks in the live slash tasks directory and you can put top rate files in there as well so in a rails project you can put things in here as well so but this is only this is something special that rails does rate by itself will do the first two and real says the second so you can split up your files and put them wherever you want to and then make some really nice to create a bunch of kind of modular things for example that tax file there is a red tasks that will go through and find all my Ruby files in my project directory and will run them through the e-tax program and created index that my editor uses to jump directly to class names and method things replace them so it's kind of nice to be able to write them and do that on almost all my projects so I just drop a tags not write file and either the rink light or the vodcasts directory so that's really nice be able to break that up okay ah here's something you should be aware of once you start breaking up things into separate files it's quite possible especially if you have not read classical computers it's quite possibly a task means that conflict with each other so rate allows you to put your test who's in a namespace now we didn't do it in that example that well the mac and cheese example but however to me going through the aperture is very important and I feel it should be a part of my great father and so I create a namespace called Apple it's just the namespace command here the : Apple was a do block everything within that view end block is within the namespace Apple so I can have a task called go to store within this namespace it is entirely separate from the task go to store outside of the namespace if you make modular dot rake files to and drop into a lot of different projects and not have a conflict I recommend putting all your tasks within a namespace so you don't conflict with other drop-in right classes you might have to invoke something in the namespace you just say great Apple : casting namespace : task name enum nested namespaces as deep as you want to go that doesn't matter and so I can still get to the original go to store or I can get to the Apple go to store tasks separately and they remain independent they don't interfere one another my great fear was people will start creating these modular rake tasks and they start combining them and we have accidental dependencies between disk casting that task and this this is a solution so let's talk more about environment rape is a command line how many people here work a lot with um Oh awesome how many people who use an IDE like Ruby mine okay Ruby mine has a ready execution sitting on that right yeah so you can do it either way if you are knitting in line you have a possibility that you can change the directory you're at and for example if you're in a rails like project you might have an app directory with models in it you might CD change directory down is your models file and you're here what happens when you type rip DB migrate in there because the rate file isn't in that directory now therefore you ever using it mate or even ant I believe is the same yes yeah that if the ant file or the make file is not in the directory where you should have to man it gets all confused Rick is this will be bit smarter than that if you say for example rake DB migrate here while you're currently there while you're Carlos in the models while rapist smart enough so there is no Rick Bob here to go up to the app directory tailor there's no rate filing here but Lopes the project director says oh here's my Red Cloud this is why I need to be so we'll find the right file and then you'll say this is the directory from which I run commands so no matter where you are you can be nested you see deep deep down into your project directory if you run rape rape will run as if it was started from the top directory there that means whatever you reference a file you only need to give the relative past from the project director has raped always runs from the project director so that makes file manipulation it's a little bit easier you don't have to worry about where are you issue the command and it changes as you navigate your tree I would really like that feature okay here we're demonstrating the fact that written notes where your admin goes to the project directory so if we create a task here called show current directory and in there we have one Ruby code that's puts out the PWD is the print working directory command in UNIX so those will print out your working directory and if we CD down into models and do the print working directory here you see it knows that we're in the models record however when you run rape show current directory and runs PWD and PWD knows it's in the main mac-and-cheese project directory so just demonstrating and in fact works like okay how about command-line you rape lots of options are great I'm going to talk about just a few of them one that people don't know a lot about is the - P command Rick - P will give you a list of all your tasks in defining your Rick files in your doctrine file and it'll tell you what they depend upon so here we can read this it says boiled water depends upon by pasta and by cheese by cheese depends upon go store go to store buy pasta depends upon go to store go to store doesn't depend on anything so you're giving the list up up the main casts are and plot they depend upon so gives you easy uses to kind of actually construct a little graph of all the tasks in there so that's that's a really handy command if you want to know absolutely everything is in the finding your father's command you see everything now another really nice command is the - key but - T is a little different it only tells you about document and tasks so if you want to clump it your tasks so you could put up with this Ruby right so you can put a hash character and do it for character and put a comment in your a file and that's fine if you're reading the right file but brick itself can't see those comments and in order for it to report to you what a description of the task you have to do at that description and that's merely the de SC command describe command and that goes right before our task and you just give it a string so the make mac and cheese description is right before the mac and cheese task by some delicious cheese buy quality pasta boil the water and you notice go to store hasn't no description at all and bother to talking about that was kind of an internal task that people of need to know about and so when I run rank - Tia tells me about all the tasks that are document so you get the mac and cheese the buying tasks and you get the boil water cast there believe they're stored in alphabetically and you get a little comment telling you exactly what they do so you can give it as much description as you launch it right there now the output of this command is cleverly designed so you can go and you can like highlight break buy cheese and paste it with your command line without typing anything extra so I was actually purposely designed to do that so it's convenient but notice we go to stores not in there because that's ask them we didn't document it so it doesn't come out with great - deep if you're if you've ever done this on a rails project you know that you've got a gazillion tasks in a rake and you can you could wrap through those if you're looking for a particular one but you can also just say a string on the dash T option and it will find those tasks that have that string so if I wanted to wear all the by pasts are you can say - t buy he'll tell me break about cheese and break by pasta this is really handy a lot of times in rails I want to know about all the DB commands are so rate - t DB : will give me all the TP commands that DB migrate the DB rollback the DV tests prepare commands yeah question the best buy you the name does not look does not look at the description for the match only matches in the name not down here's here's the DD command actually and this is actually truncated quite sharp there's many more commands okay here's a cool - man this just recently put in a rake if you've got a recent version or break you can ask their fare in the world as this task to find and you can say - done you give it a task name and it'll say oh that task is in this file on in this it's on line 19 of our particular rig file here so that's really handy if you want to know where something's defined he'll do this now unfortunately this only works with document cast and the other day I wanted to find where some undocumented task was to find him it wouldn't find it that's a blog I see we'll fix that in the next version of rape okay environment variables you can pass information to break other than just task names which is really convenient then rails a lot of times you say like rails underscore me and V equals tests or something like that well this is how that works rails is cotton isn't in environment variables so I can set an environment variable like this and then I can represent was him the rape file as well it's just the env Mac and Ruby provides to us normally so I can just get the environment variables normally like this so if I set stuff to X Y Z Z Y and show it and then print it out it will show me this stuff as X Y Z Z Y now this is setting and exporting an environment variable to shell this works in Max and Linux I'm sure what Windows does you do this in Windows the command lines there's something similar okay you can't okay I'm not I don't know it's a very handy way of doing this now there's a shortcut to this that's all she'll be okay this is all the faceless shell there's nothing you look great you're short notice you can actually say stuff is la rig show stuff and that will assign stuff but only for the execution of this command that kind of goes away out with it so it's not exported anywhere else so you can pass one off things into it and that works as well however there's one more way you can do that if you put it on the rate command line rate is smart enough to say oh look there's something on my command line that has an equal sign in it that means that what to set the environment variable rate we'll go ahead and set the environment variable and purely as if it were set outside the program so you can pass in a bunch of things like this bum rail Z and B is passed in like this in rails the when you roll back you can pass in a version number like this on DB roll backs this is used a lot the past additional information then there's also a way to pass it to your already mr. Kaster but it's kind of outside the boot camp territory so we'll save that for the advanced class yeah when it's in front like this Michelle is handling it and sending it in the environment passing it into Ruby they're doing like this rate is handling it but the effect to you as a writer of past is the same doesn't matter okay yes yes I says I have ten minutes left and since I started five minutes short I'm gonna rush here a little bit yes no it's not there's only seven eternally to get execution of yeah yeah you can it's hard to do though actually because this but that's Judas company I'm getting to that okay cool so some of our examples we have simple foot statements as the actions of tasks you know all we can do is puts that be kind of silly and wouldn't be very interesting so let's talk about the kinds of things that you can do is break actions and there's actually quite a bit first of all it's Ruby code you can do anything you want to in the test here I'm calculating the factorial as the body of the factorial task I pass in the number of the factorial that I love to calculate in there as an environment variable it calculates so anything you can imagine a Ruby you can do okay so first off so there's no limits what you do it or any task okay keep that in mind however this couple things that are really convenient to do in a red cast one of them is founded emulation and there is a final utils utility in the standard library it comes with things like copy copy recursive move make directory all the standard command line file manipulation commands are part of finally tells read takes all those that makes them directly available so you can say make the dirt copy or copy recursive in there and here suppose I wanted to make a backup create a directory copy my rate file into a copy all my rape flight products into it the nice thing about doing this is that if you wanted to so notice everything gets printed out everything rape does that's printed out here if you wanted to do silently put it in a verbose block or set the verbose on the copy command or the make their current all these file utilities follow this power could you makes me be quiet are Ramos's English and here then you get nothing for you do if you like your commands to run silently ah this is everything the file details lots of things so look up the Ruby documentation of apology kills everything is there available at the top level of and a great cast this is convenient for you to be also a lot of times you want to run shell commands now here I'm going to get stats seems to be silly to type great gift underscore spouse or you could just type get status but as an example okay you can run shell commands using SSH command that obeys the same for most flags and all the other finally kills follow so this is trying to built-in to rate for specifically running stuff in the shell also if you want to run a ruby command there is a ruby command that will run the same Ruby interpreter than is interpreting rate will hook that same interpreter on whatever a ruby program you specify so it just loads in Tehran okay almost out of time just a couple ideas other types of things I do is great we have this awesome website called get immersion that teaches you get and it is essentially a bunch of pages of navigation where you go through several labs effectives over 50 last in this and if you notice it has things like to get commands here then the actual output of the GUP command right there we build this dynamically using race so what we do we have a script file that contains all the labs in a single file and it says okay these are the things you executed we're under it there's a wreck task to run that and to generate all the output from the commands that are in the script file so we generate the output dynamically so we know it's character for character correct its whatever version of again we're using at the time then there's another red casting tape the runner script again and take the examples and build HTML files out of that link the HTML files together so the forward and backward files all like so if we add a new lab in the middle and all weaves it together very nicely we have a third rig task that'll take the whole thing and publish it as github pages and get hot so that's where we put it so the whole process is automated through great just using the couple casts that read all these things together it's an awesome tool for building all kinds of really interesting stuff like this you can use it in your rails thing to take content and maybe on buildings to MLS that pages out of it you can analyze your source code visited you can generate all kinds of things use rate use your imagination and it's sick amount of time oh yeah I'm here the whole day
Info
Channel: Confreaks
Views: 12,882
Rating: undefined out of 5
Keywords: railsconf, railsconf2012, ruby (programming language), rake
Id: AFPWDzHWjEY
Channel Id: undefined
Length: 31min 54sec (1914 seconds)
Published: Wed Jun 20 2012
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.