Compony

screenshot of Compony

Compony is a Gem that allows you to write your Rails application in component-style fashion. It combines a controller action and route along with its view into a single Ruby class. DRY your code, using inheritance even in views and much easier refactoring for your Rails applications, helping you ...

Overview

Compony is a gem designed to enhance the efficiency and clarity of Ruby on Rails applications by allowing developers to adopt a component-style architecture. By combining controller actions, routes, and views into a single Ruby class, Compony aims to streamline code organization, making it easier to maintain and refactor. It promotes a more semantic approach to coding, ensuring that developers can write DRYer code while effectively utilizing inheritance in views. This framework is built to integrate seamlessly with Rails, providing flexibility in application development.

The versatility of Compony allows developers to transition into this component system gradually while retaining the ability to work with traditional Rails routes, controllers, and views. This adaptability is particularly appealing for those looking to evolve their existing applications without a complete overhaul. Moreover, with support for Rails 7 and above, including integration with Stimulus and Turbo Drive, Compony is positioned as a modern solution for Rails development.

Features

  • Component Structure: A Compony component consolidates routes, controller actions, and views into a single class, enhancing code organization and readability.
  • DRY Code Principles: Developers can refactor common logic into reusable components, reducing code duplication and fostering cleaner code practices.
  • Model Mixin: Allows for semantic metadata definition in models, facilitating more intuitive and expressive code that reacts to the model's attributes.
  • Field Management: Compony fields help capture attributes for UI visibility and support formatting behaviors and parameter sanitization for various data types, such as URLs and phone numbers.
  • Feasibility Framework: Prohibits actions based on conditions, disabling UI buttons and providing meaningful error messages when necessary, ensuring a better user experience.
  • Gradual Integration: Compony allows existing Rails applications to incorporate components incrementally, enabling a smoother transition without requiring extensive rewrites.
  • Rails Compatibility: Fully supports Rails versions 7 to 8, along with compatibility for Turbo Frames and Streams, enhancing modern feature utilization.
  • Authorization Integration: Uses CanCanCan for authorization, allowing developers to incorporate custom authentication mechanisms tailored to their application's needs.