Sha256: df8ab1f8005b290450941f01272762fd3330a8eda0fb9cd56e1264359e06416e

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module Pakyow
  module Routes
    module Restful
      include Pakyow::Routes

      template :restful do
        resource_id = ":#{@group}_id"

        nested_path { |path| File.join(path, resource_id) }
        view_path = nested_path.gsub(/:[^\/]+/, '').split('/').reject { |p| p.empty? }.join('/')

        fn :reset_view_path do
          begin
            presenter.path = File.join(view_path, 'show') if @presenter
          rescue Presenter::MissingView
          end
        end

        get :list, '/'
        get :new,  '/new'
        get :show, "/#{resource_id}", before: [:reset_view_path]

        post :create, '/'

        get :edit, "/#{resource_id}/edit"
        patch :update, "/#{resource_id}"
        put :replace, "/#{resource_id}"
        delete :remove, "/#{resource_id}"

        group :collection
        namespace :member, resource_id

        post_process do
          # the show route is weird; move it to the end of get routes to avoid conflicts
          if show_index = @routes[:get].find_index { |route| route[2] == :show }
            @routes[:get] << @routes[:get].delete_at(show_index)
          end
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pakyow-core-0.11.3 pakyow-core/lib/pakyow/core/route_template_defaults.rb
pakyow-core-0.11.2 pakyow-core/lib/pakyow/core/route_template_defaults.rb
pakyow-core-0.11.1 pakyow-core/lib/pakyow/core/route_template_defaults.rb
pakyow-core-0.11.0 pakyow-core/lib/pakyow/core/route_template_defaults.rb
pakyow-core-0.10.2 pakyow-core/lib/core/route_template_defaults.rb
pakyow-core-0.10.1 pakyow-core/lib/core/route_template_defaults.rb
pakyow-core-0.10.0 pakyow-core/lib/core/route_template_defaults.rb