Module: ModuleBuilder::Buildable::ClassMethods
- Defined in:
- lib/module_builder/buildable.rb
Overview
Gives a module that mixes in Buildable a small DSL for specifying the class to use when building the module and the ability to easily build a new copy of the module using a given state.
Instance Method Summary collapse
-
#builder(builder_class = :not_set) ⇒ Class
Sets and accesses the builder class for a buildable module.
-
#included(descendant) ⇒ void
Includes the default version of the built module when included without a constructor.
-
#new(state = {}) ⇒ Module
Builds a module with the configured builder class using the given state.
Instance Method Details
#builder(builder_class = :not_set) ⇒ Class
When used as a class method, it declaratively sets the builder class. When used without a parameter, it uses the ‘:not_set` symbol as a marker to set itself into reader mode.
Sets and accesses the builder class for a buildable module.
37 38 39 40 41 42 43 |
# File 'lib/module_builder/buildable.rb', line 37 def builder(builder_class = :not_set) if builder_class.equal?(:not_set) builder_or_fail else @builder = builder_class end end |
#included(descendant) ⇒ void
This method returns an undefined value.
Includes the default version of the built module when included without a constructor.
62 63 64 |
# File 'lib/module_builder/buildable.rb', line 62 def included(descendant) descendant.__send__(:include, new) end |
#new(state = {}) ⇒ Module
Builds a module with the configured builder class using the given state.
83 84 85 |
# File 'lib/module_builder/buildable.rb', line 83 def new(state = {}) builder.new(state).module end |