class Bauk::Gen::Module
This class is the base module that all others should extend from. It contains methods for generating items and creating default config. It itself is not a valid module as modules need names All config for a module needs to be in the config modules->#name It takes 3 arguments:
-
Calling generator
-
Config generated by the generator
-
Map of options This map contains the possible keys:
-
disable_by_default: Whether to not enable this generator unless the
config explicity sets this value to true or a hash. e.g {modules:{moduleA:true}
-
Public Class Methods
# File lib/bauk/gen/module.rb, line 29 def initialize(generator, config, map = {}) @generator_config = config @generator = generator @map = map end
Public Instance Methods
Function to tell the calling generator whether this module is active andshould be used to generate items. It depends on whether the config privided
# File lib/bauk/gen/module.rb, line 49 def active? if @map[:disable_by_default] then @config else !@config.eql?(false) end end
# File lib/bauk/gen/module.rb, line 35 def config return @config if @config @config = default_config.deep_merge! @generator_config @config = @generator_config @config[:modules] ||= {} @config[:modules][name] ||= {} @config[:modules][name] = {} if config[:modules][name].eql? true # Overwrite values with this module values @config = @config.deep_merge! @config[:modules][name] config end
This function contains the default list of inputs It defaults to using the inputs from the root generator
# File lib/bauk/gen/module.rb, line 62 def input_generators @generator.input_generators end
This function gets the items from the inputs. It does so by itterating though each input and passing it the global list of items to add to.
# File lib/bauk/gen/module.rb, line 69 def input_items(items) log.info "Inputting items from module: #{name} (#{self.class.name})" input_generators.each do |i_gen| i_gen.new(self, config).input_items(items) end end
Method to get generator name from class
# File lib/bauk/gen/module.rb, line 77 def name return @name if @name @name = underscore(self.class.name.split('::').join('_').sub(/_*module$/i, '')).to_sym raise "Invalid nameless module provided: #{self.class.name}" if @name.empty? @name end
Method to check validate the config being provided to the generator. This overrride also takes an argument of the generator config in case default values want to be derived.
# File lib/bauk/gen/module.rb, line 58 def validate_config(_generator_config); end