How laserlemon/figaro works
Main Components
• Core Figaro Library:
• This includes the main module (lib/figaro.rb) alongside key components like Figaro::Env, Figaro::Error, and Figaro::Application.
• Its responsibility is to load a Git‑ignored YAML configuration file and inject its key/value pairs into the ENV for the Rails application.
• CLI Module:
• Found under lib/figaro/cli (with submodules for install and heroku_set), this component provides command-line tooling to install Figaro (creating the YAML file) and to easily configure remote environments (like Heroku) from that YAML file.
• The bin/figaro executable connects the CLI commands to these underlying functions.
• Rails Integration:
• This area, located under lib/figaro/rails, contains the Railtie (which hooks into Rails initialization) and Rake tasks (like lib/figaro/rails/tasks.rake).
• It ensures that when used in a Rails app, Figaro seamlessly loads configuration and integrates with the Rails configuration process.
• Tests/Specs (Verification Layer):
• Although not part of the runtime architecture, the spec directory (with RSpec tests) demonstrates how each component is tested, ensuring the behaviors of CLI commands, environment loading, and Rails integration are correct.
Relationships and Interactions
• The CLI Module is the entry point when Figaro is invoked from the command line (via the bin executable). This module calls into the Core Library to handle file reading, YAML parsing, and setting ENV variables.
• The Core Library accesses and processes the configuration file while managing errors and providing a convenient interface (including “bang” methods) to access ENV values.
• The Rails Integration component (via its Railtie and tasks) hooks into the Rails initialization process. It may also leverage the core functionality to load configuration data during application startup.
Architectural Patterns and Design Principles
• Separation of Concerns:
• The architecture clearly distinguishes between command-line operations (CLI), core logic, and Rails-specific functionality.
• Modularity:
• Each directory and module (core, CLI, rails, etc.) is encapsulated, meaning changes in one area (like CLI commands) have minimal impact on others.
• Convention over Configuration:
• Figaro advocates using a single YAML file and environment variables, following the Twelve-Factor App methodology.
Relevant Technologies and Frameworks
• Ruby as the implementation language, with the gem structure defined via the gemspec (figaro.gemspec).
• RSpec for testing (all files in the spec directory).
• Rails integration via Railtie and Rake tasks.
• Heroku integration via CLI commands (e.g., figaro heroku:set).
Final Touches and Details
• Every component has clear labels and a brief description if space allows.