class Bali::Printer

module that would allow all defined rules to be printed for check

Constants

SEPARATOR
SUBTARGET_TITLE_SEPARATOR

Public Class Methods

pretty_print() click to toggle source
# File lib/bali/printer.rb, line 15
def self.pretty_print
  printable
end
printable() click to toggle source
# File lib/bali/printer.rb, line 11
def self.printable
  instance.printable
end

Public Instance Methods

load_rule_classes() click to toggle source
# File lib/bali/printer.rb, line 19
def load_rule_classes
  return unless Bali.config.rules_path.present?

  Dir["#{Bali.config.rules_path}/**/*.rb"].each do |rule_class_path|
    require rule_class_path
  end
rescue LoadError
  # ignore
end
print_role(role, target_io) click to toggle source
printable() click to toggle source
# File lib/bali/printer.rb, line 29
def printable
  load_rule_classes
  output = StringIO.new

  # build up the string for pretty printing rules
  rule_classes = ObjectSpace.each_object(Class).select { |cls| cls < Bali::Rules }
  rule_classes.sort! { |a, b| a.to_s <=> b.to_s }
  rule_classes.each do |rule_class|
    output << "===== #{rule_class.model_class} =====\n\n"

    rule_class.ruler.roles.each do |subtarget, role|
      print_role role, output
    end

    output << "\n\n"
  end

  output << DateTime.now.strftime("Printed at %Y-%m-%d %I:%M%p %Z")

  output.string
end