class Molder::Template
Attributes
attributes[RW]
command[RW]
config[RW]
indexes[RW]
name[RW]
options[RW]
Public Class Methods
new(config:, name:, indexes:, attributes: {}, command:, options: {})
click to toggle source
# File lib/molder/template.rb, line 6 def initialize(config:, name:, indexes:, attributes: {}, command:, options: {}) self.config = config self.name = name self.indexes = indexes self.command = command self.options = options self.attributes = self.class.normalize(attributes) end
normalize(attrs)
click to toggle source
# File lib/molder/template.rb, line 25 def self.normalize(attrs) override = {} attrs.each_pair do |key, value| if value.is_a?(Hash) && value.values.compact.empty? override[key] = value.keys.to_a.join(',') end end attrs.merge!(override) end
Public Instance Methods
each_command() { |cmd| ... }
click to toggle source
# File lib/molder/template.rb, line 15 def each_command indexes.map do |i| self.attributes[:number] = i self.attributes[:formatted_number] = sprintf(config.global.index_format, i) ::Molder::Renderer.new(command.args, options).render(attributes.dup).tap do |cmd| yield(cmd) if block_given? end end end