Class: Covered::Policy::Autoload

Inherits:
Object
  • Object
show all
Defined in:
lib/covered/policy.rb

Overview

Lazily loads a report class when it is first used.

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Autoload

Initialize an autoloaded report with the given constant name.



92
93
94
# File 'lib/covered/policy.rb', line 92

def initialize(name)
	@name = name
end

Instance Method Details

#callObject

Instantiate the report and call it. Arguments are forwarded to the report.



112
113
114
# File 'lib/covered/policy.rb', line 112

def call(...)
	self.new.call(...)
end

#newObject

Instantiate the report class.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/covered/policy.rb', line 98

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

#to_sObject

A human-readable representation of this autoloaded report.



118
119
120
# File 'lib/covered/policy.rb', line 118

def to_s
	"\#<#{self.class} loading #{@name}>"
end