class Covered::Policy::Autoload
Lazily loads a report class when it is first used.
def call(...)
Instantiate the report and call it.
def call(...) self.new.call(...) end
def initialize(name)
Initialize an autoloaded report with the given constant name.
def initialize(name) @name = name end
def new
Instantiate the report class.
def new begin klass = Covered.const_get(@name) rescue NameError require_relative(snake_case(@name)) end klass = Covered.const_get(@name) return klass.new end
def snake_case(string)
def snake_case(string) return string.gsub(/::/, "/"). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end
def to_s
A human-readable representation of this autoloaded report.
def to_s "\#<#{self.class} loading #{@name}>" end