Ruby on Rails
Lightning Talk: Isolate Packages with Packwerk

Summarized using AI

Lightning Talk: Isolate Packages with Packwerk

Dorian Marie • April 12, 2021 • online

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.

Lightning Talk: Isolate Packages with Packwerk
Dorian Marie • April 12, 2021 • online

RailsConf 2021

00:00:04.940 Hi! I'm Dorian Marie, and I'm French. I work at Dr. Lee, a healthcare company where we help patients book their doctors and assist doctors in managing their practices. It's a great company to work for!
00:00:21.000 Today, this talk is going to be about Packwork and Red Packages. So, what is a package? Essentially, a package is a group of classes.
00:00:28.140 Packages can include various classes and services that you can organize for easier management. They allow you to create components, and that's what Packwork calls packages.
00:00:39.660 But why is it important to isolate packages? If you have tightly coupled packages that depend heavily on one another, it can be difficult to manage changes. When packages have minimal public APIs, it becomes easier to reason about, understand, and refactor your code.
00:01:03.899 In the graph, the dots represent classes while the lines represent references from one class to another. The very bottom layer shows a lot of references between packages, indicating tight coupling, which we want to avoid.
00:01:31.740 There are two main concepts to consider: privacy and dependency. Dependency occurs when a package needs an external class that exists outside of it, whereas privacy is involved when a class tries to access a class inside its own package.
00:01:46.680 For instance, in my package, if I have a class called 'Event' which serves as a model in my Rails app, it represents a dependency issue. On the other hand, if an event occurs from a private class within my package, that's a privacy issue.
00:02:09.539 Setting up Packwork is quite easy. You simply need to install the gem. After installing Packwork, you'll manage your application as one package while being able to create multiple internal packages.
00:02:28.920 In the configuration file for your package, the key points will include information about dependencies and guidelines on the privacy structure. Private classes should not be included in the main application package.
00:02:50.580 Let's say we create our first package and define our components. These components will reside in a directory called 'public,' which will hold the classes that are publicly accessible from anywhere in our application.
00:03:05.760 Once we've outlined the privacy and dependencies in our package configuration file, it is crucial to understand how to utilize these classes. When we call the 'Event' class while enforcing dependency checks, the system needs to recognize it correctly for our components.
00:03:56.519 If we run the dependency checks, and the system identifies all calls correctly, we won’t encounter any dependency violations. In complex packages, it's possible to declare dependencies between different packages, but managing them properly is essential.
00:04:33.720 You can find more detailed information on managing dependencies and other functions related to Packwork on their GitHub page or my website. Thank you for listening!
Explore all talks recorded at RailsConf 2021
+65