00:00:25.210
I'll go ahead and introduce myself while we're waiting since since this is not
00:00:30.740
really pertinent information you it's okay I start early what people wandered him my name's Jim Wyrick I'm with edge
00:00:37.760
case I am the chief scientist at edge case now you may be aware that that case
00:00:45.590
was just purchased this year by digital rocker forming a new company called new contacts in that case is one of the
00:00:52.190
companies in the new context grouping of companies and my new boss Mike Mike the
00:00:59.840
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
00:01:06.050
title under the new regime he says oh yes what would you like I decided that
00:01:11.060
rather than chief scientist I would like to go as chief mad scientist and he felt
00:01:18.650
that was too much of a bump up so we're deciding to go as cold mats
00:01:24.240
like the sheriff position with someone else but the position hasn't been filled yet sorry both jobs right now so I was
00:01:33.630
Ash case I'm here to talk about rape we call this basic way from I submitted a
00:01:40.200
proposal but I realize that that's so much information to give you is more like a boot camp type thing so rather
00:01:46.530
basic drink go the whole basic training boot camp thing and I'm gonna just tell you a little bit about Rick and the
00:01:52.110
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
00:01:58.230
using break entirely wrong it's the whole you're doing it wrong things so I'm not here to correct all that how
00:02:04.500
many people here but your rails developers right so you use break down a little bit up to maybe some luck yeah
00:02:10.110
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
00:02:16.050
of rape and users are going to give it's just some of these basic stuff about
00:02:21.120
rape and how it works and and how you can use rate to improve your life so
00:02:27.000
rate is a tool for organizing tasks tests are things that you need to have
00:02:32.760
done so I'm going to start with kind of an overall what kind of an important
00:02:38.910
task right so I'm hungry let's make some mac and cheese okay so what do I have to
00:02:46.410
do to make myself some some macaroni cheese well first I've got to have some
00:02:52.739
some pasta available I have to have some cheese available and I got a boil the
00:02:58.260
water to make it so these are some of the subtasks that might be involved in and put it together mac and cheese meal
00:03:04.410
now there are dependencies here in order to make mac and cheese that depends upon
00:03:09.570
all these of a 10 so this is the essence of rate is take a task and break it down
00:03:15.630
to its component pieces and specify what needs to be done in order to do the
00:03:21.510
bigger task that you're trying to involve so so if you took this and run it out
00:03:26.640
right rate filing who look exactly like this would specify I have my main task here mac and cheese and every task gets
00:03:35.220
a title this is just Ruby code it's in a rate five got our meatball but it is
00:03:41.400
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
00:03:47.459
could also be strings or it doesn't care and so every task has a name every task
00:03:53.340
has an action that action is encoded was a do end block that gets executed to
00:03:59.250
perform that task and then finally tasks have dependencies and we specify
00:04:04.830
dependencies with just strange kind of arrow syntax you say well that looks really weird but if you think about
00:04:11.580
that's just hash syntax where it kind of uses a syntax quirk of Ruby in that did
00:04:18.090
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
00:04:24.810
the keys that with the task name and the list that's the value in the hash pair
00:04:30.540
there that's just the list of dependencies so it's just a syntax check that Rick uses so you just left off the
00:04:39.210
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
00:04:46.590
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
00:04:52.680
first task like there rape mac and cheese and we see coming out of the screen boiling water bypass the buy
00:04:59.669
cheese and then making the mac and cheese anybody see a problem with this
00:05:05.750
I've you know I started by water boiling and then they run out to the store and I
00:05:11.400
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
00:05:18.340
probably but probably don't want to start the boiling water first so if we want their dependencies what we see is
00:05:24.280
that we've missed some dependencies and what we really want to say is that before I boil the water I want to make
00:05:31.450
sure I have on hand both the cheese in the past all the ingredients that go into making that so
00:05:37.210
I want to specify these dependencies as well so I need to go back into my rake file and add these dependencies to the
00:05:43.420
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
00:05:49.360
get magically buying the pasta by the cheese bought in the water and making
00:05:54.730
the mac and cheese to get all like dependency right dependencies right reaches automatically does the right
00:06:01.720
thing I realized I never started my timer and it's really cool timer on my
00:06:11.710
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
00:06:18.190
that they got an extra five minutes now on the baking path making mac and cheese okay so getting the dependencies right
00:06:23.740
is important in rate so check declare all the dependencies if something must
00:06:29.950
be done before any other task make them explicit dependency and just declare and
00:06:35.470
then raping the magic but make sure things get done in the right order now I do want to point out that each of
00:06:42.850
these things are individual cast and although I say rick mac and cheese i could have very well have said rape by
00:06:50.200
cheese and when it would have done just that task so you can invoke individual tasks or you could invoke the big task
00:06:56.920
that depends upon everything either way will work okay sup nice dick
00:07:03.940
about us I realized that I probably broke this down a little bit incorrectly maybe I should have another task in
00:07:10.960
there called go to the store because in order to buy the cheese and buy the possible actually have to go somewhere
00:07:16.390
and maybe I need to have some work done this cognitive both buying cheese and
00:07:21.880
buying pasta so let's add that is another task and now there's dependencies between buy cheese and buy
00:07:27.100
pasta and go to the store so I'm there where I think buy the cheese now we run
00:07:34.270
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
00:07:41.020
then we also add two dependencies - cheese and pasta so then it depends upon
00:07:46.660
whether the source of going to the store will be done first before either of these passes to run so I run it I
00:07:53.350
magically get the right thing going to the start by the pasta by the cheese one of the water making the master cheaper
00:07:58.560
think about that didn't I have I have two dependencies of good at the store
00:08:04.650
why didn't I go to the store twice let's
00:08:11.950
work through how great handles dependencies so I specified mac and
00:08:17.200
cheese is my first dependency so great whoops at that passed and says oh well coming to make mac and cheese I see
00:08:22.540
there are three dependencies on that achieves I must satisfy all the tendencies first before I can make the
00:08:29.200
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
00:08:36.970
oh I need to borrow the boil water has two dependencies I need to look at each of this dependencies and make sure they
00:08:43.060
are satisfied first and the first one is by pasta this is a look and you see a
00:08:48.520
pattern here we must go to the store first as a prerequisite so let's focus on that past
00:08:54.910
and this is okay go to store has requisites I can actually do the go to
00:09:00.319
the store work right now because there are no dependencies that needs to have this wine so we put check that one off
00:09:07.490
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
00:09:13.490
and run back now my pasta all this dependencies have been satisfied so we can click that one off our list we go
00:09:20.209
back up to chain is a big boil water it has to depend sees one of which has been
00:09:25.939
done the other one still needs to be executed so it will go and focus on buy
00:09:31.339
cheese it sees buy cheese has it pendency go to store but look we've
00:09:36.740
already done to go to store task doesn't need to be done again rape is smart
00:09:43.939
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
00:09:51.079
methods and you have call and you're calling out to other methods if these were methods you go to the store twice
00:09:57.309
but then rate because I just listed as dependencies that must be satisfied great news it's already satisfied and
00:10:04.670
won't run it again so we put off by cheese now boiling water is done both of
00:10:10.279
his dependencies are satisfied and now we're back up at make mac and cheese it
00:10:16.550
has three dependencies but no look the buy cheese in my toss stuff once have already been done so there's no need to
00:10:22.670
do them again and now we can click off make mac and cheese so the body for that
00:10:27.769
one it's run so rate is simply turns out that the engine that drives rate is
00:10:34.790
about 100 lines of code probably awesome and we do our 50 lines of code it just walks the tree of dependencies execute
00:10:41.509
the prerequisites and then walks back up and it kind of depth first manner actually pretty
00:10:47.510
simple coding question so far
00:10:52.780
okay that's ever done actually this is the basics this is the essence of rate
00:10:59.240
getting those dependencies right and declaring them right and so so what more
00:11:04.940
is in Drake couple things it's really convenient just to say break at the very
00:11:11.090
top level to say rate and have something do something by default so rate
00:11:16.190
recognizes a past name default and if you give it dependencies it will try to
00:11:21.470
satisfy them if you do nothing else so if you same rate with no caste on the
00:11:29.540
command line it will go to the default path and satisfy its dependency so this is a nice way of specifying rate of the
00:11:44.030
tax circularity so we'll say oh this is a sick of our dependency and will complain and groan at you until you exit
00:11:51.290
I think it does so remember Dobbs it
00:11:58.720
doesn't actually happen that often real life but you can occasionally get up and I'm trying to remember for complains
00:12:04.730
right away or it actually tries to execute it will okay so rape is a task
00:12:15.530
execution engine so let's talk about the environment in which it runs you
00:12:21.890
probably have a project directory that might look something like this the top level of your project you're going to
00:12:28.130
have a rate file and this is required this is where you put all your tasks and rate will recognize that name file and
00:12:35.450
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
00:12:41.550
there's a couple things you do number one you trade a director called rate line and put individual files in there
00:12:48.310
with an extension dot rate and R it will automatically go into that directory and
00:12:54.970
pull in those files as if they were part of the main rate file in addition if you
00:13:02.769
are running a rails project rails tells rate to look for additional tasks in the
00:13:09.670
live slash tasks directory and you can put top rate files in there as well so
00:13:15.579
in a rails project you can put things in here as well so but this is only this is
00:13:21.880
something special that rails does rate by itself will do the first two and real says the second so you can split up your
00:13:27.339
files and put them wherever you want to and then make some really nice to create
00:13:32.860
a bunch of kind of modular things for example that tax file there is a red
00:13:38.980
tasks that will go through and find all my Ruby files in my project directory
00:13:44.529
and will run them through the e-tax program and created index that my editor
00:13:49.600
uses to jump directly to class names and method things replace them so it's kind of nice to be
00:13:57.459
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
00:14:03.910
or the vodcasts directory so that's really nice be able to break that up
00:14:12.300
okay ah here's something you should be aware of once you start breaking up
00:14:19.089
things into separate files it's quite possible especially if you have not read
00:14:24.189
classical computers it's quite possibly a task means that conflict with each other so rate allows
00:14:30.530
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
00:14:36.560
example but however to me going through the aperture is very important and I feel it should be a part of my great
00:14:42.590
father and so I create a namespace called Apple it's just the namespace
00:14:47.930
command here the : Apple was a do block everything within that view end block is within the
00:14:54.590
namespace Apple so I can have a task called go to store within this namespace
00:14:59.870
it is entirely separate from the task go to store outside of the namespace if you
00:15:06.200
make modular dot rake files to and drop into a lot of different projects and not have a conflict I recommend putting all
00:15:13.280
your tasks within a namespace so you don't conflict with other drop-in right classes you might have to invoke
00:15:22.640
something in the namespace you just say great Apple : casting namespace : task
00:15:28.850
name enum nested namespaces as deep as you want to go that doesn't matter and
00:15:34.640
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
00:15:40.940
independent they don't interfere one another my great fear was people will
00:15:46.760
start creating these modular rake tasks and they start combining them and we have accidental dependencies between
00:15:52.700
disk casting that task and this this is a solution
00:15:59.640
so let's talk more about environment rape is a command line how many people
00:16:05.980
here work a lot with um Oh awesome how many people who use an IDE like Ruby
00:16:12.130
mine okay Ruby mine has a ready execution sitting on that right yeah so you can do it either way if you are
00:16:19.150
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
00:16:26.410
like project you might have an app directory with models in it you might CD change directory down is your models
00:16:31.930
file and you're here what happens when you type rip DB migrate in there because
00:16:40.870
the rate file isn't in that directory now therefore you ever using it mate or
00:16:47.080
even ant I believe is the same yes yeah that if the ant file or the make file is
00:16:52.930
not in the directory where you should have to man it gets all confused Rick is this will be bit smarter than
00:16:58.510
that if you say for example rake DB migrate here while you're currently
00:17:05.620
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
00:17:12.430
directory tailor there's no rate filing here but Lopes the project director says oh here's my
00:17:18.640
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
00:17:24.850
which I run commands so no matter where you are you can be nested you see deep
00:17:30.670
deep down into your project directory if you run rape rape will run as if it was
00:17:36.250
started from the top directory there that means whatever you reference a file
00:17:41.680
you only need to give the relative past from the project director has raped
00:17:47.410
always runs from the project director so that makes file manipulation
00:17:53.929
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
00:17:59.299
your tree I would really like that feature okay here we're demonstrating
00:18:09.710
the fact that written notes where your admin goes to the project directory so if we create a task here called show
00:18:15.499
current directory and in there we have one Ruby code that's puts out the PWD is
00:18:21.919
the print working directory command in UNIX so those will print out your working directory and if we CD down into
00:18:29.119
models and do the print working directory here you see it knows that we're in the models record however when
00:18:34.490
you run rape show current directory and runs PWD and PWD knows it's in the main
00:18:40.999
mac-and-cheese project directory so just demonstrating and in fact works like okay how about
00:18:52.879
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
00:18:59.269
lot about is the - P command Rick - P will give you a list of all your tasks
00:19:06.039
in defining your Rick files in your doctrine file and it'll tell you what
00:19:12.169
they depend upon so here we can read this it says boiled water depends upon by pasta and by cheese by cheese depends
00:19:22.220
upon go store go to store buy pasta depends upon go to store go to store
00:19:28.059
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
00:19:35.869
easy uses to kind of actually construct a little graph of all the tasks in there
00:19:41.679
so that's that's a really handy command if you want to know absolutely everything is in the finding your
00:19:47.929
father's command you see everything now another really nice command is the - key but - T is a little
00:19:54.220
different it only tells you about document and tasks so if you want to clump it your tasks so you could put up
00:20:01.990
with this Ruby right so you can put a hash character and do it for character
00:20:07.720
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
00:20:14.200
comments and in order for it to report to you what a description of the task
00:20:19.690
you have to do at that description and that's merely the de SC command describe command and that goes right before our
00:20:26.799
task and you just give it a string so the make mac and cheese description is
00:20:33.399
right before the mac and cheese task by some delicious cheese buy quality pasta boil the water and you notice go to
00:20:39.879
store hasn't no description at all and bother to talking about that was kind of
00:20:45.129
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
00:20:51.759
document so you get the mac and cheese the buying tasks and you get the boil water cast there believe they're stored
00:20:59.409
in alphabetically and you get a little comment telling you exactly what they do so you can give it as much description
00:21:05.470
as you launch it right there now the output of this command is cleverly designed so you can go and you
00:21:12.940
can like highlight break buy cheese and paste it with your command line without
00:21:18.220
typing anything extra so I was actually purposely designed to do that so it's convenient but notice we go to stores
00:21:24.429
not in there because that's ask them we didn't document it so it doesn't come out with great - deep if
00:21:31.639
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
00:21:39.679
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
00:21:47.059
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
00:21:55.639
he'll tell me break about cheese and break by pasta this is really handy a
00:22:03.529
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
00:22:12.049
that DB migrate the DB rollback the DV tests prepare commands yeah question the
00:22:18.139
best buy you the name does not look does
00:22:24.950
not look at the description for the match only matches in the name
00:22:31.400
not down here's here's the DD command actually and this is actually truncated quite sharp there's many more commands
00:22:39.550
okay here's a cool - man this just recently put in a rake if you've got a
00:22:45.140
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
00:22:52.430
a task name and it'll say oh that task is in this file on in this it's on line
00:22:57.920
19 of our particular rig file here so that's really handy if you want to know
00:23:03.590
where something's defined he'll do this now unfortunately this only works with document cast and the other day I wanted
00:23:09.770
to find where some undocumented task was to find him it wouldn't find it that's a
00:23:14.809
blog I see we'll fix that in the next version of rape okay environment variables you can pass
00:23:21.350
information to break other than just task names which is really convenient then rails a lot of times you say like
00:23:27.320
rails underscore me and V equals tests or something like that
00:23:32.900
well this is how that works rails is cotton isn't in environment variables so
00:23:38.660
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
00:23:45.460
Mac and Ruby provides to us normally so I can just get the environment variables normally like this so if I set stuff to
00:23:52.880
X Y Z Z Y and show it and then print it out it will show me this stuff as X Y Z
00:23:58.400
Z Y now this is setting and exporting an environment variable to shell this works
00:24:05.630
in Max and Linux I'm sure what Windows does you do this in Windows the command
00:24:11.510
lines there's something similar okay you can't okay I'm not I don't know
00:24:18.460
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
00:24:25.660
shell there's nothing you look great you're short notice you can actually say stuff is la rig show stuff and that will
00:24:33.550
assign stuff but only for the execution of this command that kind of goes away
00:24:38.860
out with it so it's not exported anywhere else so you can pass one off things into it
00:24:43.900
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
00:24:50.679
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
00:24:56.770
set the environment variable rate we'll go ahead and set the environment variable and purely as if it were set
00:25:02.679
outside the program so you can pass in a bunch of things like this bum rail Z and
00:25:09.610
B is passed in like this in rails the when you roll back you can pass in a
00:25:14.650
version number like this on DB roll backs this is used a lot the past additional information then there's also
00:25:21.460
a way to pass it to your already mr. Kaster but it's kind of outside the boot
00:25:26.620
camp territory so we'll save that for the advanced class yeah
00:25:39.290
when it's in front like this Michelle is handling it and sending it in the environment passing it into Ruby they're
00:25:45.630
doing like this rate is handling it but the effect to you as a writer of past is
00:25:51.330
the same doesn't matter okay yes yes I says I have ten minutes left and since I
00:25:57.420
started five minutes short I'm gonna rush here a little bit yes no it's not
00:26:06.630
there's only seven eternally to get execution of yeah yeah you can it's hard
00:26:20.460
to do though actually because this but that's Judas company I'm getting to that okay cool so some of our examples we
00:26:29.340
have simple foot statements as the actions of tasks you know all we can do is puts that be kind of silly and
00:26:34.500
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
00:26:40.500
all it's Ruby code you can do anything you want to in the test here I'm
00:26:45.930
calculating the factorial as the body of the factorial task I pass in the number
00:26:51.090
of the factorial that I love to calculate in there as an environment variable it calculates so anything you
00:26:58.170
can imagine a Ruby you can do okay so first off so there's no limits what you do it or any task
00:27:03.870
okay keep that in mind however this couple things that are really convenient to do in a red cast one of them is
00:27:10.290
founded emulation and there is a final utils utility in the standard library it
00:27:15.390
comes with things like copy copy recursive move make directory all the
00:27:21.750
standard command line file manipulation commands are part of finally tells read
00:27:27.720
takes all those that makes them directly available so you can say make the dirt copy or copy recursive in there and here
00:27:35.830
suppose I wanted to make a backup create a directory copy my rate file into a copy all my rape flight products into it
00:27:43.560
the nice thing about doing this is that if you wanted to so notice everything gets printed out everything rape does
00:27:49.600
that's printed out here if you wanted to do silently put it in a verbose block or set the verbose
00:27:56.170
on the copy command or the make their current all these file utilities follow this power could you makes me be quiet
00:28:02.830
are Ramos's English and here then you get nothing for you do if you like your
00:28:08.260
commands to run silently ah this is everything the file details
00:28:14.200
lots of things so look up the Ruby documentation of apology kills everything is there available at the top
00:28:20.560
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
00:28:26.860
here I'm going to get stats seems to be silly to type great gift underscore
00:28:32.440
spouse or you could just type get status but as an example okay you can run shell commands using SSH command that obeys
00:28:40.030
the same for most flags and all the other finally kills follow so this is trying to built-in to rate for
00:28:47.260
specifically running stuff in the shell also if you want to run a ruby command
00:28:53.040
there is a ruby command that will run the same Ruby interpreter than is interpreting rate will hook that same
00:28:59.560
interpreter on whatever a ruby program you specify so it just loads in Tehran
00:29:08.880
okay almost out of time just a couple ideas other types of things I do is great we
00:29:16.190
have this awesome website called get immersion that teaches you get and it is
00:29:21.440
essentially a bunch of pages of navigation where you go through several labs effectives over 50 last in this and
00:29:29.119
if you notice it has things like to get commands here then the actual output of the GUP command right there we build
00:29:37.429
this dynamically using race so what we do we have a script file that contains all the labs in a single file and it
00:29:44.479
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
00:29:51.440
output from the commands that are in the script file so we generate the output
00:29:56.559
dynamically so we know it's character for character correct its whatever version of again we're using at the time
00:30:02.049
then there's another red casting tape the runner script again and take the examples and build HTML files out of
00:30:09.859
that link the HTML files together so the forward and backward files all like so
00:30:15.559
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
00:30:21.919
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
00:30:28.669
through great just using the couple casts that read all these things together it's an awesome tool for
00:30:34.999
building all kinds of really interesting stuff like this you can use it in your rails thing to take content and maybe on
00:30:42.700
buildings to MLS that pages out of it you can analyze your source code visited
00:30:48.049
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
00:30:55.220
whole day