All language subtitles for pragstudio-ruby-22-distribution (Transcribed on 27-Apr-2023 20-37-42)

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified) Download
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,000 --> 00:00:04,960 Hey, it's time for the grand finale. 2 00:00:04,960 --> 00:00:09,440 Now we want to package up our code as a Ruby gem to make it easy to install and download 3 00:00:09,440 --> 00:00:11,320 and distribute to other people. 4 00:00:11,320 --> 00:00:14,760 And the first thing we need to address is that all of our classes are defined at the 5 00:00:14,760 --> 00:00:16,620 top level of our program. 6 00:00:16,620 --> 00:00:20,920 So imagine that you have our gem and it has a player class, and then you install another 7 00:00:20,920 --> 00:00:24,760 gem and it has a player class, we're going to have a naming collision. 8 00:00:24,760 --> 00:00:29,560 Yeah, so instead of defining those classes at the top level of our program, we need to 9 00:00:29,560 --> 00:00:34,120 wrap them in some sort of namespace to avoid these sort of naming collisions. 10 00:00:34,120 --> 00:00:38,200 And we've already seen how we can use modules to scope the names of things. 11 00:00:38,200 --> 00:00:39,879 So let's revisit that. 12 00:00:39,879 --> 00:00:43,120 So remember way back when we created this snackbar module. 13 00:00:43,120 --> 00:00:46,220 Inside the snackbar we had this constant called snacks. 14 00:00:46,220 --> 00:00:51,560 And then to get access to the snacks constant, we had to use this scope resolution operator, 15 00:00:51,560 --> 00:00:53,739 snackbar colon colon snacks. 16 00:00:53,739 --> 00:00:56,920 So in a way, the module is acting as a namespace. 17 00:00:56,920 --> 00:01:02,200 It avoids any collisions with other modules or classes that might have a constant called 18 00:01:02,200 --> 00:01:08,320 snacks because to access snacks you have to scope it properly within the module name. 19 00:01:08,320 --> 00:01:10,800 So we've seen that modules can have constants. 20 00:01:10,800 --> 00:01:13,600 We've also looked at modules having module methods. 21 00:01:13,600 --> 00:01:17,640 And then we also saw in the previous section how we could have methods inside of modules 22 00:01:17,640 --> 00:01:20,240 that get mixed into other classes. 23 00:01:20,240 --> 00:01:25,640 So now we want to look at the third case of modules, which is just a way to create namespaces 24 00:01:25,640 --> 00:01:27,840 to avoid these name clashes. 25 00:01:27,840 --> 00:01:31,080 So let's look at a slightly different example that I created. 26 00:01:31,080 --> 00:01:32,840 It's in namespaces.rb. 27 00:01:32,840 --> 00:01:35,080 We've got this module called movie system. 28 00:01:35,080 --> 00:01:37,700 And it has a constant called version 1.0. 29 00:01:37,700 --> 00:01:39,740 We've got a module called game system. 30 00:01:39,740 --> 00:01:43,500 It has its own constant version set to 2.0. 31 00:01:43,500 --> 00:01:48,400 They also each have a module method called info that prints out their name and their 32 00:01:48,400 --> 00:01:49,440 version. 33 00:01:49,440 --> 00:01:52,800 And then so if we want to print out the movie system version, we have to scope it to the 34 00:01:52,800 --> 00:01:53,800 movie system module. 35 00:01:53,800 --> 00:01:56,720 If we want to call the info method, we call it on the movie system. 36 00:01:56,720 --> 00:02:01,240 In the same way, to get access to the game system's version, we've got to scope it to 37 00:02:01,240 --> 00:02:02,640 the game system. 38 00:02:02,640 --> 00:02:03,899 And the same with its info method. 39 00:02:03,899 --> 00:02:08,840 So if we run this now, you notice that we get 1.0 for the movie system, 2.0 for the 40 00:02:08,840 --> 00:02:10,180 game system. 41 00:02:10,180 --> 00:02:15,079 So we've already got these neatly sort of scoped versions and different methods. 42 00:02:15,079 --> 00:02:18,000 But we can also put classes inside of modules. 43 00:02:18,000 --> 00:02:22,680 So let's say a movie system has a class called player, for example. 44 00:02:22,680 --> 00:02:27,240 And then down in our game system, we'll also define a class called player. 45 00:02:27,240 --> 00:02:31,680 Now because they're inside of a module, to instantiate objects of that type, we would 46 00:02:31,680 --> 00:02:36,480 have to call movie system colon colon player. 47 00:02:36,480 --> 00:02:39,080 That's the name of the class, which is also a constant. 48 00:02:39,080 --> 00:02:40,480 And then we would call the new method. 49 00:02:40,480 --> 00:02:47,220 In the same way, to create a game system player, we'd have to use game system colon colon player 50 00:02:47,220 --> 00:02:48,240 dot new. 51 00:02:48,240 --> 00:02:50,400 And if we run that, well, we don't get any output. 52 00:02:50,400 --> 00:02:54,760 Let me just put us in front of there. 53 00:02:54,760 --> 00:02:55,760 Run it again. 54 00:02:55,760 --> 00:02:57,600 And notice that we get distinct objects. 55 00:02:57,600 --> 00:03:02,160 In fact, the default printout here shows you this one is the movie system player, this 56 00:03:02,160 --> 00:03:04,020 one is the game system player. 57 00:03:04,020 --> 00:03:05,020 So this is good. 58 00:03:05,020 --> 00:03:09,480 It means we can have classes of the same name in our gem that could be of the same name 59 00:03:09,480 --> 00:03:13,360 in another gem, as long as we properly scope all of our classes. 60 00:03:13,360 --> 00:03:16,600 So let's go do something similar for our movie classes. 61 00:03:16,600 --> 00:03:20,840 So over in our playlist class, up at the top, there's our class definition. 62 00:03:20,840 --> 00:03:26,079 We're going to wrap all of our classes in a module called Flix. 63 00:03:26,079 --> 00:03:30,440 And then we'll just take this entire class, and we'll just go ahead and indent it a little 64 00:03:30,440 --> 00:03:31,600 bit. 65 00:03:31,600 --> 00:03:34,440 And we've got that inside of the Flix module. 66 00:03:34,440 --> 00:03:36,000 So let's look at our player spec. 67 00:03:36,000 --> 00:03:39,480 If we try to run our player spec now, ooh, we get this error. 68 00:03:39,480 --> 00:03:42,359 It says uninitialized constant playlist. 69 00:03:42,360 --> 00:03:47,920 Well, that's because playlist here is actually inside of a module called Flix. 70 00:03:47,920 --> 00:03:53,680 So we can actually wrap our entire spec in a module, Flix.rb as well, down at the bottom. 71 00:03:53,680 --> 00:03:55,120 I'll put an end. 72 00:03:55,120 --> 00:04:00,420 So this whole describe block is in the same module as our playlist class. 73 00:04:00,420 --> 00:04:04,160 And now if we run it, sure enough, all of our tests pass. 74 00:04:04,160 --> 00:04:06,320 So what if we try to run our top level program? 75 00:04:06,320 --> 00:04:10,000 Let's go out to a command line, and we run Ruby Flix.rb. 76 00:04:10,000 --> 00:04:15,040 Oh, we get the same sort of problem, uninitialized constant playlist. 77 00:04:15,040 --> 00:04:16,040 So what's that about? 78 00:04:16,040 --> 00:04:20,560 Well, let's look in Flix.rb, and we're requiring all the right files. 79 00:04:20,560 --> 00:04:23,440 But right here, we're referencing the playlist class. 80 00:04:23,440 --> 00:04:28,960 We need to reference Flix colon colon playlist, because that's the properly scoped name of 81 00:04:28,960 --> 00:04:29,960 that. 82 00:04:29,960 --> 00:04:34,000 Now when we go out and run it, we get how many viewings, and we can run our game, or 83 00:04:34,000 --> 00:04:35,640 run our movie app here. 84 00:04:35,640 --> 00:04:39,960 Now of course, we need to put all of our classes and all of our specs in the Flix namespace 85 00:04:39,960 --> 00:04:47,640 but we'll go ahead and do that and fast forward. 86 00:04:47,640 --> 00:04:48,640 Okay cool. 87 00:04:48,640 --> 00:04:51,440 So now we have no more class name clashes. 88 00:04:51,440 --> 00:04:52,440 Right, right. 89 00:04:52,440 --> 00:04:53,440 Yeah. 90 00:04:53,440 --> 00:04:57,280 Okay, so the next issue we need to address is that we have all of our files in one directory. 91 00:04:57,280 --> 00:05:01,520 We need to kind of organize that a little better so we have multiple directories. 92 00:05:01,520 --> 00:05:03,880 Yeah, so we need to put our code in one directory. 93 00:05:03,880 --> 00:05:07,000 We'd like to put our spec files in another directory. 94 00:05:07,000 --> 00:05:08,400 What to name those directories? 95 00:05:08,400 --> 00:05:14,039 Well, RubyGems has some conventions on how to organize our files to create a good gem. 96 00:05:14,039 --> 00:05:15,919 So let's go ahead and create those directories. 97 00:05:15,919 --> 00:05:16,919 Perfect. 98 00:05:16,919 --> 00:05:19,200 So we have all of our classes in modules. 99 00:05:19,200 --> 00:05:20,200 Now we're going to create some directories. 100 00:05:20,200 --> 00:05:24,320 We're just going to create a directory over here, put all of our class files in. 101 00:05:24,320 --> 00:05:30,200 The convention is to use a directory called lib, and we'll just take our class files, 102 00:05:30,200 --> 00:05:36,760 movie, everything but our specs, our playlist, rankable, all this good stuff, and we'll just 103 00:05:36,760 --> 00:05:38,719 drag it down into the lib directory. 104 00:05:38,719 --> 00:05:40,159 We've got that. 105 00:05:40,159 --> 00:05:45,760 And then our specs go in a directory called spec singular. 106 00:05:45,760 --> 00:05:52,719 We can take our movie spec here, playlist, snack bar, all those specs, drag those down 107 00:05:52,719 --> 00:05:55,000 into the spec directory. 108 00:05:55,000 --> 00:05:58,659 So what we have left is we've got our main driver program. 109 00:05:58,659 --> 00:06:01,760 Now that typically goes in a directory called bin. 110 00:06:01,760 --> 00:06:05,880 It's like a command line utility for using our gem. 111 00:06:05,880 --> 00:06:07,960 So I'll just drag that down into there. 112 00:06:07,960 --> 00:06:12,800 It's also polite to have a license file that just has the license of your code and also 113 00:06:12,800 --> 00:06:15,840 a readme file to tell people how to use your gem. 114 00:06:15,840 --> 00:06:18,080 Oh, we've also got this movies.csv. 115 00:06:18,080 --> 00:06:22,880 This is kind of like part of our command line interface, at least an example of a file that 116 00:06:22,880 --> 00:06:23,880 has movies. 117 00:06:23,880 --> 00:06:25,360 I'm going to drag that down into bin as well. 118 00:06:25,360 --> 00:06:29,719 So we've got lib, spec, and bin. 119 00:06:29,719 --> 00:06:34,659 Now remember all of our class files are in this module called flix. 120 00:06:34,660 --> 00:06:40,360 So down inside of lib, it's very handy and easy to find files if we actually mirror that 121 00:06:40,360 --> 00:06:41,360 structure here. 122 00:06:41,360 --> 00:06:44,120 So I'm going to create a folder directory under lib. 123 00:06:44,120 --> 00:06:45,440 I'm going to call it flix. 124 00:06:45,440 --> 00:06:47,160 That's the name of the module. 125 00:06:47,160 --> 00:06:52,100 And then move those files down into the flix directory. 126 00:06:52,100 --> 00:06:57,560 So that way the directory structure flix and then the file matches the module flix as well. 127 00:06:57,560 --> 00:06:59,160 I'm going to do the same thing with spec here. 128 00:06:59,160 --> 00:07:08,840 I'm going to create a folder here called flix and move those files down into flix, just 129 00:07:08,840 --> 00:07:10,760 like that. 130 00:07:10,760 --> 00:07:12,860 So now let's try to run our program from the command line. 131 00:07:12,860 --> 00:07:19,120 We'll use Ruby and then we'll have to go into the bin directory and run flix.rb and it fails. 132 00:07:19,120 --> 00:07:21,940 It says it can't load the file playlist. 133 00:07:21,940 --> 00:07:23,160 So what's going on there? 134 00:07:23,160 --> 00:07:28,720 Well, if we look at flix.rb, it's down in bin, remember that we're saying require relative 135 00:07:28,720 --> 00:07:34,080 playlist, which means it's expecting to find the playlist file relative to this file, which 136 00:07:34,080 --> 00:07:35,800 is in this directory bin. 137 00:07:35,800 --> 00:07:40,940 So we need to change this around because the playlist actually lives up one directory down 138 00:07:40,940 --> 00:07:45,880 in the lib subdirectory and then the flix directory under it. 139 00:07:45,880 --> 00:07:47,160 Now that's going to fix that up. 140 00:07:47,160 --> 00:07:52,880 But one other thing we want to do here is this file name is relative to wherever we're 141 00:07:52,880 --> 00:07:53,880 going to run this program. 142 00:07:53,880 --> 00:07:58,640 And it'd be nice if we could run it from wherever, especially when we install this in the gem. 143 00:07:58,640 --> 00:08:02,219 So we want to give this file name actually an absolute path. 144 00:08:02,219 --> 00:08:07,520 The way we can do that is I'm going to say default movie file is equal to, and I'm going 145 00:08:07,520 --> 00:08:12,280 to use the file class again and we can join some paths together here. 146 00:08:12,280 --> 00:08:16,340 I want the directory of the current file. 147 00:08:16,340 --> 00:08:21,120 That will be the bin directory, the directory where this flix.rb file lives. 148 00:08:21,120 --> 00:08:27,159 And I want to join onto that, then the name movies.csv. 149 00:08:27,160 --> 00:08:30,080 And that's going to resolve to an absolute path. 150 00:08:30,080 --> 00:08:34,920 So then we can pass that in as our default movie file. 151 00:08:34,920 --> 00:08:42,040 So no matter where we run flix.rb, it's going to be able to find this movies.csv file because 152 00:08:42,040 --> 00:08:46,240 it's going to have an absolute path down to our current directory. 153 00:08:46,240 --> 00:08:47,240 Save this away. 154 00:08:47,240 --> 00:08:52,100 We should be able to go run our program and it's working as it did before. 155 00:08:52,100 --> 00:08:55,840 Now it'd be nice to be able to run this, especially if we distribute this as a gem. 156 00:08:55,840 --> 00:09:01,320 Instead of saying ruby bin flix.rb, it'd be nice to be able to run it kind of like a command 157 00:09:01,320 --> 00:09:04,620 in the same way that we were able to run rspec as a command. 158 00:09:04,620 --> 00:09:06,580 It doesn't have a.rb extension. 159 00:09:06,580 --> 00:09:08,760 We don't have to type in ruby before that. 160 00:09:08,760 --> 00:09:09,760 So how would we do that? 161 00:09:09,760 --> 00:09:16,480 Well, we could move or just rename our flix.rb file to just flix. 162 00:09:16,480 --> 00:09:19,600 So we'll just take off the rb extension. 163 00:09:19,600 --> 00:09:22,500 If we look at bin, sure enough, it's now called flix. 164 00:09:22,500 --> 00:09:27,280 So now we can run ruby bin flix and our program runs. 165 00:09:27,280 --> 00:09:29,960 So how do we get rid of typing in ruby before that? 166 00:09:29,960 --> 00:09:35,240 Well, if we go over to the flix file, at the top of this, we can put this little incantation. 167 00:09:35,240 --> 00:09:42,980 It's called a shebang notation and we just say we want to run usr bin env ruby. 168 00:09:42,980 --> 00:09:49,280 So that says when you run this file, use the environment to find the ruby interpreter. 169 00:09:49,280 --> 00:09:50,720 Go back to the command line. 170 00:09:50,720 --> 00:09:57,080 We're going to change the mode on this file so that it's executable. 171 00:09:57,080 --> 00:09:58,960 This is a Unix thing. 172 00:09:58,960 --> 00:10:03,860 And now we can just run bin slash flix. 173 00:10:03,860 --> 00:10:04,860 So it looks like a little command. 174 00:10:04,860 --> 00:10:10,320 You don't have to type in ruby, no rb extension, and it's running our movie app. 175 00:10:10,320 --> 00:10:15,880 And when people install this as a gem, they'll just be able to run flix as a command, just 176 00:10:15,880 --> 00:10:18,160 like typing in rspec. 177 00:10:18,160 --> 00:10:21,920 Now before we get ready to distribute our gem, we should probably check that all of 178 00:10:21,920 --> 00:10:23,400 our specs run. 179 00:10:23,400 --> 00:10:25,040 That's a really good idea. 180 00:10:25,040 --> 00:10:26,199 So let's just try it. 181 00:10:26,199 --> 00:10:27,199 Rspec. 182 00:10:27,199 --> 00:10:32,199 Ooh, it can't even run our specs right now. 183 00:10:32,199 --> 00:10:34,420 It can't load the files or even find them. 184 00:10:34,420 --> 00:10:35,420 So what's going on there? 185 00:10:35,420 --> 00:10:37,819 Well, let's go look over at our specs. 186 00:10:37,819 --> 00:10:39,640 Movie3dspec.rb, for example. 187 00:10:39,640 --> 00:10:43,720 We've got it inside of a module, but notice that we're using require relative inside of 188 00:10:43,720 --> 00:10:47,839 our specs and movie3d isn't relative to this file. 189 00:10:47,840 --> 00:10:48,840 So we need to change this. 190 00:10:48,840 --> 00:10:56,080 And what happens is our spec will automatically add the lib and the spec directory to Ruby's 191 00:10:56,080 --> 00:10:57,600 load path. 192 00:10:57,600 --> 00:11:01,800 So by doing that, we can just call require because require is going to look at Ruby's 193 00:11:01,800 --> 00:11:08,640 load path, try to find a file, and we're going to require flix slash because that's going 194 00:11:08,640 --> 00:11:11,440 to be relative to the lib directory. 195 00:11:11,440 --> 00:11:12,680 That's on the load path. 196 00:11:12,680 --> 00:11:15,180 We've got to go down and find it under flix. 197 00:11:15,180 --> 00:11:20,400 So we need to change all of our specs now to use require, which I'll just do real quick. 198 00:11:20,400 --> 00:11:24,680 This one's going to be require flix.movey. 199 00:11:24,680 --> 00:11:32,040 Our playlist is going to require flix slash playlist. 200 00:11:32,040 --> 00:11:35,560 And our snack bar, change that one around real quick. 201 00:11:35,560 --> 00:11:38,079 It'll be flix, just like that. 202 00:11:38,079 --> 00:11:43,280 Now, if we go back out to the command line and clean that up, we should be able to run 203 00:11:43,280 --> 00:11:47,120 rspec and now all of our test paths. 204 00:11:47,120 --> 00:11:51,880 You notice that we didn't have to type rspec dot because rspec will automatically look 205 00:11:51,880 --> 00:11:54,800 in the spec directory for all of our specs. 206 00:11:54,800 --> 00:11:59,800 Okay, so now that we have all of our files organized according to the Ruby gem convention, 207 00:11:59,800 --> 00:12:01,699 we're ready to write our Ruby gem. 208 00:12:01,699 --> 00:12:04,240 But the first thing we need to create is a gem spec. 209 00:12:04,240 --> 00:12:07,880 Yeah, we've got the directories there, but Ruby gems needs a little bit more information 210 00:12:07,880 --> 00:12:10,520 about our gem before it can actually use it. 211 00:12:10,520 --> 00:12:14,400 So we'll write a gem spec file, I actually already have one prepared, and then we'll 212 00:12:14,400 --> 00:12:16,980 use it to actually create the Ruby gem. 213 00:12:16,980 --> 00:12:18,439 So let's look at that. 214 00:12:18,439 --> 00:12:19,880 So here's our gem spec file. 215 00:12:19,880 --> 00:12:25,480 It's in a file called flix dot gem spec, and it's a little, basically a little domain specific 216 00:12:25,480 --> 00:12:28,720 language for specifying what your gem is and what it does. 217 00:12:28,720 --> 00:12:31,560 And it's pretty straightforward and fairly self-explanatory. 218 00:12:31,560 --> 00:12:33,920 We've got the name, which is always lowercase. 219 00:12:33,920 --> 00:12:36,160 We're going to call our gem flix. 220 00:12:36,160 --> 00:12:42,120 It has the version number, which I've set to 1.0, author, email, a really short summary 221 00:12:42,120 --> 00:12:43,439 of what the gem does. 222 00:12:43,439 --> 00:12:46,000 A longer summary goes in description. 223 00:12:46,000 --> 00:12:49,319 And you notice because this is a Ruby file, I can actually use Ruby code. 224 00:12:49,319 --> 00:12:54,959 So I'm going to say file read, and I'm actually reading the contents of the readme file that's 225 00:12:54,959 --> 00:12:58,520 in our directory, which has more of a description about this gem. 226 00:12:58,520 --> 00:12:59,800 So that'll be put in that field. 227 00:12:59,800 --> 00:13:01,600 We've got our homepage. 228 00:13:01,600 --> 00:13:04,959 Then we list all the files that are associated with this gem. 229 00:13:04,960 --> 00:13:07,760 And I've used another little Ruby mechanism here. 230 00:13:07,760 --> 00:13:14,200 I've used the dir class, and I'm using a wildcard match here saying, give me all the files in 231 00:13:14,200 --> 00:13:16,240 bin and lib and spec. 232 00:13:16,240 --> 00:13:17,240 It'll put those together. 233 00:13:17,240 --> 00:13:22,760 Plus, notice I'm using this little shortcut array syntax to create an array that has the 234 00:13:22,760 --> 00:13:24,960 license and the readme in it. 235 00:13:24,960 --> 00:13:28,680 And then I'm concatenating that array onto the array of all the other files. 236 00:13:28,680 --> 00:13:33,720 So this just creates one big array, all the files that are in our gem. 237 00:13:33,720 --> 00:13:36,400 I've also listed all of our test files. 238 00:13:36,400 --> 00:13:38,140 Those are down in the spec directory. 239 00:13:38,140 --> 00:13:43,400 What our executable name is, the executable's name is flix because the previous thing we 240 00:13:43,400 --> 00:13:45,200 called it flix. 241 00:13:45,200 --> 00:13:49,560 And then really important for this gem, we're saying that we're requiring Ruby version greater 242 00:13:49,560 --> 00:13:55,120 than or equal to 1.9 because we're using things like require relative, which are only supported 243 00:13:55,120 --> 00:13:56,480 in Ruby 1.9. 244 00:13:56,480 --> 00:14:02,160 Also, just as a little hint here, I said add development dependency R spec. 245 00:14:02,160 --> 00:14:06,400 And development dependencies aren't installed by default, so they're not activated when 246 00:14:06,400 --> 00:14:10,959 the gem is used, but it's nice to put in any development level dependencies. 247 00:14:10,959 --> 00:14:13,560 So now that we have that, we can go build our Ruby gem. 248 00:14:13,560 --> 00:14:16,839 I'm just going to save that, go over to the terminal session here. 249 00:14:16,839 --> 00:14:22,360 And the way we create our gem is we say gem build, give it the name of our gem spec. 250 00:14:22,360 --> 00:14:25,560 All right, it said it successfully built Ruby gems. 251 00:14:25,560 --> 00:14:32,119 And if I look inside of this directory, I now have this flix dash the version name and 252 00:14:32,119 --> 00:14:33,959 then dot gem. 253 00:14:33,959 --> 00:14:36,959 So then we can go ahead and install it locally as a test. 254 00:14:36,959 --> 00:14:40,680 And we just do gem install and give it the name of that file. 255 00:14:40,680 --> 00:14:42,640 It's just a local gem file. 256 00:14:42,640 --> 00:14:45,479 It's going to install it right here on my box. 257 00:14:45,479 --> 00:14:46,839 And I can do a gem list. 258 00:14:46,839 --> 00:14:51,760 I'm going to search for the flix gem and just give a little bit of description there or 259 00:14:51,760 --> 00:14:53,160 details about that. 260 00:14:53,160 --> 00:14:57,520 And sure enough, you see it says flix 100 and it has some of that information that we 261 00:14:57,520 --> 00:14:59,740 had inside of the gem spec. 262 00:14:59,740 --> 00:15:04,120 So now if I open a new terminal window, just to get out of this directory structure, so 263 00:15:04,120 --> 00:15:07,439 there's nothing on my sleeve here, I've got the gem installed here. 264 00:15:07,439 --> 00:15:11,959 I can just type flix because remember that's the name of that command we created in the 265 00:15:11,959 --> 00:15:14,400 bin directory and it's part of the gem. 266 00:15:14,400 --> 00:15:17,160 We listed it in the gem spec as an executable. 267 00:15:17,160 --> 00:15:20,060 And if I type that, we have our movie app running. 268 00:15:20,060 --> 00:15:25,280 So I want one listing, it found our movies.csv file, loaded it up, and we've got all of our 269 00:15:25,280 --> 00:15:27,119 three movies being played here. 270 00:15:27,119 --> 00:15:29,239 I'll just quit out of there. 271 00:15:29,239 --> 00:15:32,599 And then when I'm done with the gem or if I don't want it installed on my box, I can 272 00:15:32,599 --> 00:15:36,280 just say gem uninstall flix. 273 00:15:36,280 --> 00:15:37,280 It has this executable. 274 00:15:37,280 --> 00:15:39,699 It's also going to ask me if I want to remove that. 275 00:15:39,699 --> 00:15:42,300 Sure enough, and the gem is uninstalled. 276 00:15:42,300 --> 00:15:45,880 Now at this point, we can share our gem file with anyone. 277 00:15:45,880 --> 00:15:47,680 We can send it to them in a file. 278 00:15:47,680 --> 00:15:48,680 We can email. 279 00:15:48,680 --> 00:15:50,160 We can put it on a server to download. 280 00:15:50,160 --> 00:15:52,520 Yeah, let's actually put it up on a public server. 281 00:15:52,520 --> 00:15:56,560 We'll put it on rubygems.org where most of all the public gems live. 282 00:15:56,560 --> 00:15:57,560 Perfect. 283 00:15:57,560 --> 00:16:01,520 So you'll need an account on rubygems.org, but after you have an account, you can push 284 00:16:01,520 --> 00:16:03,560 the gem file to their public server. 285 00:16:03,560 --> 00:16:04,560 So let's do that. 286 00:16:04,560 --> 00:16:06,120 We say gem push. 287 00:16:06,120 --> 00:16:07,920 We give it the name of the file. 288 00:16:07,920 --> 00:16:11,300 We've got it living there, our gem file. 289 00:16:11,300 --> 00:16:12,920 And it went ahead and pushed it up there. 290 00:16:12,920 --> 00:16:16,359 It registered the gem as flix 1.0.0. 291 00:16:16,359 --> 00:16:18,079 I can go ahead and search for it. 292 00:16:18,080 --> 00:16:22,480 I'm going to search for the remote server flix, not the one that's installed locally. 293 00:16:22,480 --> 00:16:24,520 In fact, we uninstalled it. 294 00:16:24,520 --> 00:16:25,520 Remote gems. 295 00:16:25,520 --> 00:16:26,520 It's going to go looking for flix. 296 00:16:26,520 --> 00:16:28,680 There it is, flix 1.0.0. 297 00:16:28,680 --> 00:16:32,780 And we can go ahead and install it from rubygems.org. 298 00:16:32,780 --> 00:16:34,880 And it went ahead and installed it. 299 00:16:34,880 --> 00:16:38,140 So let me just go to a different directory just outside of this directory just to show 300 00:16:38,140 --> 00:16:39,460 that the gem is installed. 301 00:16:39,460 --> 00:16:42,520 We can type flix again and got our movie app running. 302 00:16:42,520 --> 00:16:45,040 Got all of our movies inside of there. 303 00:16:45,040 --> 00:16:46,760 Or we could actually use this as a library. 304 00:16:46,760 --> 00:16:48,280 Let's load up IRB. 305 00:16:48,280 --> 00:16:53,800 And then we can say require flix playlist. 306 00:16:53,800 --> 00:16:55,080 It's our playlist class. 307 00:16:55,080 --> 00:16:56,120 And it says true. 308 00:16:56,120 --> 00:16:57,439 And then we could actually create a playlist. 309 00:16:57,439 --> 00:16:59,360 Let's create one. 310 00:16:59,360 --> 00:17:01,560 It's inside the flix module. 311 00:17:01,560 --> 00:17:03,439 Let's create one for gonzo. 312 00:17:03,439 --> 00:17:04,440 Gonzo's playlist. 313 00:17:04,440 --> 00:17:05,440 Like that. 314 00:17:05,440 --> 00:17:06,680 Now we've got a playlist. 315 00:17:06,680 --> 00:17:08,000 Let's create a movie. 316 00:17:08,000 --> 00:17:10,660 It's inside the flix module as well. 317 00:17:10,660 --> 00:17:13,240 Let's create a Muppets movie. 318 00:17:13,240 --> 00:17:14,240 The Muppets. 319 00:17:14,240 --> 00:17:17,760 It's got to have a rank of at least 10. 320 00:17:17,760 --> 00:17:23,280 And now we can call playlist.addmovie movie. 321 00:17:23,280 --> 00:17:28,280 And playlist will play one iteration of those. 322 00:17:28,280 --> 00:17:33,120 So we can use our gem either as a command line utility or as a standalone library. 323 00:17:33,120 --> 00:17:35,280 We can just load up the classes and use those. 324 00:17:35,280 --> 00:17:36,280 Okay. 325 00:17:36,280 --> 00:17:37,280 So this is it. 326 00:17:37,280 --> 00:17:42,920 This is your first ruby gem, your last exercise, and your big moment to show off your new ruby 327 00:17:42,920 --> 00:17:43,920 skills. 328 00:17:43,920 --> 00:17:46,600 Now you might want to cue up some of your favorite tunes while you're working through 329 00:17:46,600 --> 00:17:50,880 this exercise because in the end we expect you to do a victory dance. 330 00:17:50,880 --> 00:17:53,160 And you might be wondering where you go from here. 331 00:17:53,160 --> 00:17:56,560 We'll come on back and we're going to help you out with that in the next section. 332 00:17:56,560 --> 00:18:14,159 See you then. 29249

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.