Class: Covered::Policy::Autoload
- Inherits:
-
Object
- Object
- Covered::Policy::Autoload
- Defined in:
- lib/covered/policy.rb
Overview
Lazily loads a report class when it is first used.
Instance Method Summary collapse
-
#call ⇒ Object
Instantiate the report and call it.
-
#initialize(name) ⇒ Autoload
constructor
Initialize an autoloaded report with the given constant name.
-
#new ⇒ Object
Instantiate the report class.
-
#to_s ⇒ Object
A human-readable representation of this autoloaded report.
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
#call ⇒ Object
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 |
#new ⇒ Object
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_s ⇒ Object
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 |