class ShouldaRouting::Resources::Base

Attributes

block[RW]
current[RW]
options[RW]

Public Class Methods

new(*args, &block) click to toggle source
# File lib/shoulda_routing/resources/base.rb, line 7
def initialize *args, &block
  @options = args.extract_options!
  @current = args
  @block   = block
end

Public Instance Methods

test!() click to toggle source
# File lib/shoulda_routing/resources/base.rb, line 13
def test!
  Routes::STACK.resources.push(current)

  Routes::STACK.routes.each do |route|
    specs_for(routeable_actions, route)
    specs_for(unrouteable_actions, route, :not_to)
  end

  DSL.instance_eval(&block) if block
  Routes::STACK.resources.pop
end

Private Instance Methods

actions() click to toggle source
# File lib/shoulda_routing/resources/base.rb, line 40
def actions
  {
    :index   => { via: :get },
    :create  => { via: :post },
    :new     => { via: :get, path: "/new" },
    :edit    => { via: :get, path: "/1/edit", params: { id: "1" }},
    :show    => { via: :get, path: "/1", params: { id: "1" }},
    :update  => { via: :put, path: "/1", params: { id: "1" }},
    :destroy => { via: :delete, path: "/1", params: { id: "1" }}
  }
end
routeable_actions() click to toggle source
# File lib/shoulda_routing/resources/base.rb, line 52
def routeable_actions
  @routeable_actions ||= begin
    routeable_actions = actions.keys
    routeable_actions = actions.keys & Array(options[:only]) if options[:only]
    routeable_actions = actions.keys - Array(options[:except]) if options[:except]
    actions.select{ |action, args| routeable_actions.include?(action) }
  end
end
specs_for(actions, route, spec_method = :to) click to toggle source
# File lib/shoulda_routing/resources/base.rb, line 27
def specs_for actions, route, spec_method = :to
  actions.each do |action, args|
    Routes::Spec.execute do |config|
      config.via        = args[:via]
      config.path       = route[:url] + (args[:path] || "")
      config.controller = options[:controller] || route[:controller]
      config.action     = action
      config.params     = route[:params].merge(args[:params] || {})
      config.method     = spec_method
    end
  end
end
unrouteable_actions() click to toggle source
# File lib/shoulda_routing/resources/base.rb, line 61
def unrouteable_actions
  @unrouteable_actions ||= begin
    actions.select{ |action, args| !routeable_actions.include?(action) }
  end
end