A Ruby library that simplifies creating and using Domain Specific Languages (DSLs) by elegantly handling context switching.
Docile is a Ruby library that simplifies the creation and execution of Domain Specific Languages (DSLs). It elegantly handles the context switching between a DSL object and the block's original scope, allowing developers to write expressive DSLs without complex meta-programming. It solves the problem of accessing methods and variables from both contexts seamlessly.
Ruby developers who are building or using internal DSLs, such as those creating configuration libraries, builder patterns, or any project requiring a clean, expressive API.
Developers choose Docile because it abstracts away the tricky meta-programming required for context-aware DSL execution, providing a reliable and easy-to-use interface that supports both mutable and immutable objects, nested DSLs, and block parameters.
Docile keeps your Ruby DSLs tame and well-behaved
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows methods, local variables, and instance variables from the block's context to be accessed within the DSL, eliminating the need for complex meta-programming to handle scope, as shown in the Array example.
Correctly chains method and variable handling across nested DSL evaluations, enabling recursive structures like the person tree example without breaking context.
Provides both `dsl_eval` for mutable objects and `dsl_eval_immutable` for functional, immutable DSLs, catering to different programming paradigms as demonstrated with PizzaBuilder and String examples.
Enables parameters to be passed into DSL blocks, facilitating dispatcher patterns like in the Sinatra-like routing example for flexible DSL designs.
The additional layer for context-aware execution introduces slight performance penalties compared to using raw `instance_eval`, which may matter in latency-sensitive applications.
Adds a gem dependency to your project, which could be a drawback for minimalist setups or when avoiding third-party libraries for maintenance reasons.
Primarily designed for Ruby's block-based DSLs, so it might not integrate well with non-block DSL approaches or languages outside Ruby, limiting its versatility.