Class: Mack::Routes::ResourceProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/mack/routing/resource_proxy.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, resources = []) ⇒ ResourceProxy

Returns a new instance of ResourceProxy.



11
12
13
14
15
# File 'lib/mack/routing/resource_proxy.rb', line 11

def initialize(controller, resources = [])
  self.controller = controller
  self.routes = []
  self.resources = resources
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



17
18
19
# File 'lib/mack/routing/resource_proxy.rb', line 17

def method_missing(sym, *args)
  connect(sym, *args)
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



7
8
9
# File 'lib/mack/routing/resource_proxy.rb', line 7

def controller
  @controller
end

#resourcesObject

Returns the value of attribute resources.



9
10
11
# File 'lib/mack/routing/resource_proxy.rb', line 9

def resources
  @resources
end

#routesObject

Returns the value of attribute routes.



8
9
10
# File 'lib/mack/routing/resource_proxy.rb', line 8

def routes
  @routes
end

Instance Method Details

#resource(name, options = {}, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/mack/routing/resource_proxy.rb', line 21

def resource(name, options = {}, &block)
  if block_given?
    proxy = Mack::Routes::ResourceProxy.new(name, [self.resources, name].flatten)
    yield proxy
    proxy.routes.each do |route|
      Mack::Routes::RouteMap.instance.connect_with_name("#{name}_#{route[:name]}", route[:path], options.merge(route[:options]))
    end
  end
  Mack::Routes::RouteMap.instance.build_resource_routes(name, compile_path(name, self.resources), name, options)
end