Sha256: b6876eaac92063f8b392368c4ba63216afb1c44518e59f66f8750e50476fa22c

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

# TODO: gotta be a better way than copying everything
require 'action_dispatch/routing/mapper'

module ActionDispatch::Routing::Mapper::Resources
  def resource(*resources, &block)
    options = resources.extract_options!.dup

    options[:controller] = resources.first if satellite?

    if apply_common_behavior_for(:resource, resources, options, &block)
      return self
    end

    resource_scope(:resource, SingletonResource.new(resources.pop, options)) do
      yield if block_given?

      concerns(options[:concerns]) if options[:concerns]

      collection do
        post :create if parent_resource.actions.include?(:create)
        post :run if satellite?
      end

      new do
        get :new
      end if parent_resource.actions.include?(:new)

      set_member_mappings_for_resource
    end

    self
  end

  def resources(*resources, &block)
    options = resources.extract_options!.dup

    options[:controller] = resources.first if satellite?

    if apply_common_behavior_for(:resources, resources, options, &block)
      return self
    end

    resource_scope(:resources, Resource.new(resources.pop, options)) do
      yield if block_given?

      concerns(options[:concerns]) if options[:concerns]

      collection do
        get  :index if parent_resource.actions.include?(:index)
        post :create if parent_resource.actions.include?(:create)
        post :run if satellite?
      end

      new do
        get :new
      end if parent_resource.actions.include?(:new)

      set_member_mappings_for_resource
    end

    self
  end

  def satellite?
    @scope[:as] == 'satellites'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lunar_shell-0.5.2 lib/lunar_shell/core_ext/action_dispatch.rb
lunar_shell-0.5.0 lib/lunar_shell/core_ext/action_dispatch.rb
lunar_shell-0.4.1 lib/lunar_shell/core_ext/action_dispatch.rb
lunar_shell-0.3.0 lib/lunar_shell/core_ext/action_dispatch.rb