Class: Canned::ControllerExt::ControllerProxy::ActorLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/canned/controller_ext.rb

Overview

Allows actors to be served on demand, provides a hash–like interface to TestContext through ControllerProxy.actors method.

Instance Method Summary collapse

Constructor Details

#initialize(_controller, _loaders) ⇒ ActorLoader

Returns a new instance of ActorLoader.



195
196
197
198
199
# File 'lib/canned/controller_ext.rb', line 195

def initialize(_controller, _loaders)
  @controller = _controller
  @loaders = _loaders
  @actor_cache = {}
end

Instance Method Details

#[](_key) ⇒ Object



201
202
203
204
205
206
207
208
209
# File 'lib/canned/controller_ext.rb', line 201

def [](_key)
  _key = _key.to_sym
  return @actor_cache[_key] if @actor_cache.has_key? _key

  loader = @loaders[_key]
  raise Canned::SetupError.new "Invalid actor loader value" if loader.nil?
  actor = if loader.is_a? String then @controller.send(loader) else @controller.instance_eval(&loader) end
  @actor_cache[_key] = actor
end

#has_key?(_key) ⇒ Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/canned/controller_ext.rb', line 211

def has_key?(_key)
  @loaders.has_key? _key.to_sym
end