List

Lightning Talks: Dorian Marie

Lightning Talks: Dorian Marie

by Dorian Marie

In this Lightning Talk presented by Dorian Marie at RailsConf 2021, the main theme revolves around understanding package management within Ruby on Rails applications using the Packwerk tool.

The key points discussed include:

- Introduction to Packwerk: Dorian explains what a package is—a group of classes and files—and how it can help manage services and components within an application.

- Importance of Package Isolation: The talk emphasizes the need to isolate packages. This isolation can make it easier to reason about code, understand its structure, and facilitate easier modifications and refactoring.

- Technical Concepts: Dorian introduces two primary concepts in package management: privacy and dependency. Privacy issues arise when a package tries to access a class within itself, whereas dependency issues occur when a class from one package calls another class from an external package.

- Setting Up Packwerk: The process of setting up Packwerk is straightforward. Dorian outlines the necessary steps including installing the gem, setting up the package.yml file, and organizing application components into distinct packages.

- Public Classes and Access Control: The distinction between public classes, which can be used throughout the application, and private classes is crucial for maintaining clean architecture. Dorian discusses how public classes should be organized and notes the importance of enforcing dependencies in the package management system.

- Running Packwerk Checks: The talk describes how to perform checks on the package's structure through Packwerk. This ensures that there are no incorrect dependencies or privacy issues in the code when referencing classes across different packages.

Throughout the presentation, technical details are provided alongside real-world application scenarios, helping to illustrate the practical benefits of using Packwerk in a Rails app. The closing remarks encourage viewers to delve deeper into Packwerk and explore its documentation on GitHub and the speaker's website. The overall takeaway emphasizes the organizational benefits and improved code maintainability that accompany properly managed package systems in Rails applications.

RailsConf 2021

00:00:04.940 hi uh I'm doing I'm French I work at Dr
00:00:09.179 Lee but like a Healthcare Company
00:00:10.860 patients we book their doctors and
00:00:12.960 doctors they manage their Apartments
00:00:14.639 it's great it's an awesome company if
00:00:17.520 you want to work with me on Earth
00:00:21.000 um okay so this talk is gonna be about
00:00:22.859 Park work and or two is red packages so
00:00:25.920 what is the package uh package is
00:00:28.140 basically a group of classes so
00:00:31.019 um all of files I guess no more classes
00:00:34.800 and
00:00:36.480 um
00:00:37.140 and so you can have services for
00:00:39.660 instance that you can put into packages
00:00:41.579 uh you can you can create components
00:00:43.920 whatever uh backward calls them package
00:00:46.980 packages so the idea is why why do you
00:00:49.980 want to isolate packages is uh but if
00:00:53.340 you have like in the first picture on
00:00:54.780 the right uh if you have uh packages
00:00:58.020 that are tightly covered between in each
00:01:00.960 other and what uh that have a little
00:01:03.899 public API uh
00:01:08.420 it's easier to reason about it's easier
00:01:11.640 to understand it's easier to change and
00:01:13.979 it's easier to refactor in this graph
00:01:17.100 the dots are the classes the the the
00:01:19.860 lines are the reference from a class to
00:01:22.680 another class and the basically the cube
00:01:25.020 that will package so you can see the
00:01:26.759 bottom one is there's a lot of reference
00:01:28.560 between packages and it's their ID
00:01:31.740 copper so anyway uh there are two
00:01:35.700 concepts in a in a paragraph privacy and
00:01:39.299 dependency so it's not called it's a
00:01:42.659 fake it's fake code but uh if if when
00:01:46.680 when the dependency is when the package
00:01:49.680 occurred an external class that is
00:01:52.439 outside the package so for instance in
00:01:55.380 my package called the class event that's
00:01:57.540 a model in my Razor app it's a
00:01:59.640 dependency issue and and if my event uh
00:02:03.720 occurs a private class in my package
00:02:07.140 it's a privacy issue because it's trying
00:02:09.539 to to find a class inside my package
00:02:13.099 now to setup is very easy you install
00:02:15.900 the gem you better install you you need
00:02:18.300 pack work and then when you edit back we
00:02:20.459 actually have three things the bean pack
00:02:22.680 work is like usual uh to execute back
00:02:25.739 work a package.tml because your world
00:02:28.920 application becomes one package and in
00:02:31.739 this package we are going to be like
00:02:33.060 many packages so uh so the package in
00:02:37.140 first dependencies uh and those are the
00:02:40.260 info privacy because it doesn't
00:02:42.900 basically you don't you don't put the
00:02:44.879 private class in uh in the in the
00:02:47.280 application package itself and the
00:02:50.580 important part is is in the
00:02:52.200 backtrack.tml in the load path I added
00:02:54.480 components so I call them components
00:02:56.040 instead of packages in my app and and so
00:02:59.700 so after that uh let's say we create we
00:03:02.819 create our first package we make these
00:03:05.760 components uh further that's gonna
00:03:08.780 contain all our components we make
00:03:11.400 inside uh uh a package called event
00:03:15.420 filter and inside uh to a directory
00:03:18.720 called a public so a public is is going
00:03:21.720 to be aware our public classes are going
00:03:23.819 to be the classes that are going to be
00:03:25.620 able to be occurred from uh anywhere in
00:03:28.920 a uh in a in our in our app uh so we end
00:03:33.060 for the privacy on first the dependency
00:03:35.580 in the package.tml file and so we and so
00:03:39.599 this package like for instance if we
00:03:41.700 find if we put the content uh this
00:03:43.980 content so the card is not important the
00:03:46.140 important part is at the end of the file
00:03:48.060 we call the event
00:03:50.099 so uh let's see what happens if we call
00:03:53.099 the event class uh and while we have the
00:03:56.519 enforce dependency
00:03:58.620 so when we run back backward check uh we
00:04:02.280 uh we have a very we have a variation
00:04:04.459 and uh it says that you can call a event
00:04:08.720 uh class that belongs to the main app
00:04:12.000 from the component from the package so
00:04:15.599 it's a different simulation but so we we
00:04:19.019 can use something we can do it manually
00:04:21.060 or we can use something called by
00:04:23.280 backward update depreciation and it
00:04:25.800 would it will uh automatically find the
00:04:28.320 the dependencies and and the the
00:04:30.900 variation in general and and it would
00:04:33.720 register them and uh so in this example
00:04:37.020 it really is to register ovulation of
00:04:39.419 dependency uh but we call the event that
00:04:42.600 belongs to the main application from our
00:04:45.479 our event filter file class
00:04:49.400 uh and then once once we have updated
00:04:52.320 our depreciation we run packwell Parkway
00:04:54.960 check and no offense is detected okay we
00:04:59.040 can you can have complex packages per
00:05:01.199 class uh moving variations if you want
00:05:03.900 by a packet you can use raison giant uh
00:05:08.160 and uh you can declare dependency
00:05:09.900 between package and but it's dependent
00:05:12.180 on that works that's a bad news and you
00:05:15.720 can read more on GitHub uh the back work
00:05:17.940 and on my website thank you