Class: Canned::ControllerExt::ControllerProxy

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

Overview

ActionController - TestContext adapter

Defined Under Namespace

Classes: ActorLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_controller) ⇒ ControllerProxy

Returns a new instance of ControllerProxy.



165
166
167
168
169
170
# File 'lib/canned/controller_ext.rb', line 165

def initialize(_controller)
  @controller = _controller
  @resources = ActiveSupport::HashWithIndifferentAccess.new
  # actors are provided throug a dynamic loader.
  @actors = ActorLoader.new _controller, _controller.class._cn_actors
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_method, *_args, &_block) ⇒ Object

 Proxies messages to wrapped controller.



173
174
175
# File 'lib/canned/controller_ext.rb', line 173

def method_missing(_method, *_args, &_block)
  @controller.send(_method, *_args, &_block)
end

Instance Attribute Details

#actorsObject (readonly)

Returns the value of attribute actors.



163
164
165
# File 'lib/canned/controller_ext.rb', line 163

def actors
  @actors
end

#resourcesObject (readonly)

Returns the value of attribute resources.



162
163
164
# File 'lib/canned/controller_ext.rb', line 162

def resources
  @resources
end

Instance Method Details

#preload_resources_for(_action) ⇒ Object

Loads resources required by _action



178
179
180
181
182
183
184
185
186
187
# File 'lib/canned/controller_ext.rb', line 178

def preload_resources_for(_action)
  _action = _action.to_sym
  Array(@controller.class._cn_resources).each do |res|
    next unless res[:only].nil? or res[:only].include? _action
    next unless res[:except].nil? or !res[:except].include? _action

    @resources[res[:name]] = resource = @controller.instance_eval &res[:loader]
    @controller.instance_variable_set "@#{res[:name]}", resource
  end
end