Class: Aws::Templates::Utils::Lazy
- Inherits:
-
Module
- Object
- Module
- Aws::Templates::Utils::Lazy
show all
- Defined in:
- lib/aws/templates/utils/autoload.rb
Overview
Lazy module wrapper
Allows to traverse non-existent modules up to the point when constant can be auto-discovered.
Constant Summary
Constants included
from Autoload
Autoload::MODULE_LOCKER, Autoload::REQUIRE_LOCKER, Autoload::Trace
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Module
#ancestors_with
Methods included from Autoload
_check_if_required, _try_to_require, atomic_require, autoload!, const_is_loaded?, const_path_for, sanitize_load_exception
Constructor Details
#initialize(parent, short_name = nil) ⇒ Lazy
Returns a new instance of Lazy.
206
207
208
209
210
|
# File 'lib/aws/templates/utils/autoload.rb', line 206
def initialize(parent, short_name = nil)
raise ScriptError.new("#{parent} is not a module") unless parent.is_a?(Module)
@parent = parent
@short_name = short_name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *params, &blk) ⇒ Object
160
161
162
163
|
# File 'lib/aws/templates/utils/autoload.rb', line 160
def method_missing(method_name, *params, &blk)
raise_error(method_name, params, blk)
super
end
|
Class Method Details
.fail_on_method(method_name) ⇒ Object
124
125
126
|
# File 'lib/aws/templates/utils/autoload.rb', line 124
def self.fail_on_method(method_name)
define_method(method_name) { |*params, &blk| raise_error(method_name, params, blk) }
end
|
Instance Method Details
#const_missing(const_name) ⇒ Object
169
170
171
|
# File 'lib/aws/templates/utils/autoload.rb', line 169
def const_missing(const_name)
Lazy.new(self, const_name)
end
|
#inspect ⇒ Object
184
185
186
|
# File 'lib/aws/templates/utils/autoload.rb', line 184
def inspect
"#{name}(Lazy)"
end
|
#lazy ⇒ Object
188
189
190
|
# File 'lib/aws/templates/utils/autoload.rb', line 188
def lazy
self
end
|
#name ⇒ Object
192
193
194
195
196
197
198
199
200
|
# File 'lib/aws/templates/utils/autoload.rb', line 192
def name
return @parent.name if @short_name.nil?
if @parent.root_namespace?
@short_name.to_s
else
"#{@parent.name}::#{@short_name}"
end
end
|
#raise_error(method_name, params, blk) ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/aws/templates/utils/autoload.rb', line 128
def raise_error(method_name, params, blk)
raise NoMethodError.new(
"Lazy namespace #{self} doesn't support #{method_name}\n" \
" Parameters: #{params}\n" \
" Block: #{blk}"
)
end
|
#reduce(is_loaded = false) ⇒ Object
173
174
175
176
177
178
|
# File 'lib/aws/templates/utils/autoload.rb', line 173
def reduce(is_loaded = false)
return @parent.reduce if @short_name.nil?
@parent.reduce(is_loaded || Autoload.const_is_loaded?(@parent, @short_name))
.const_get(@short_name)
end
|
#respond_to_missing? ⇒ Boolean
165
166
167
|
# File 'lib/aws/templates/utils/autoload.rb', line 165
def respond_to_missing?(*)
super
end
|
#root_namespace? ⇒ Boolean
202
203
204
|
# File 'lib/aws/templates/utils/autoload.rb', line 202
def root_namespace?
@parent.root_namespace? && @short_name.nil?
end
|
#to_s ⇒ Object
180
181
182
|
# File 'lib/aws/templates/utils/autoload.rb', line 180
def to_s
name
end
|