Class: MerbResourceScope::Controller::ScopedResourceMixin::ResourceScope

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-resource-scope/controller/scoped_resource_mixin.rb

Overview

Proxy class to provide a consistent API for resource_scope. passing all method calls to the current_scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ResourceScope

Returns a new instance of ResourceScope.



47
48
49
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 47

def initialize(controller)
  @controller = controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 67

def method_missing(method, *args, &block)
  if current_scope.respond_to?(method)
    current_scope.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



45
46
47
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 45

def controller
  @controller
end

Instance Method Details

#_current_specificationObject



55
56
57
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 55

def _current_specification
  @_current_specification ||= controller._current_specification
end

#_enclosing_resourceObject



51
52
53
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 51

def _enclosing_resource
  @_enclosing_resource ||= controller.enclosing_resource
end

#current_scopeObject



63
64
65
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 63

def current_scope
  @current_scope ||= _enclosing_resource ? _enclosing_resource.send(_current_specification.association_method) : _current_specification.klass
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/merb-resource-scope/controller/scoped_resource_mixin.rb', line 59

def respond_to?(method)
  super || current_scope.respond_to?(method)
end