Module: Waves::Mapping::PrettyUrls::GetRules

Defined in:
lib/mapping/pretty_urls.rb

Overview

GetRules defines the following URL conventions:

/resources            # => get a list of all instances of resource
/resource/name        # => get a specific instance of resource with the given name
/resource/name/editor # => display an edit page for the given resource

Class Method Summary collapse

Class Method Details

.included(target) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mapping/pretty_urls.rb', line 20

def self.included(target)

  target.module_eval do

    extend Waves::Mapping

    name = '([\w\-\_\.\+\@]+)'; model = '([\w\-]+)'

    # get all resources for the given model
    path %r{^/#{model}/?$}, :method => :get do | model |
      resource( model.singular ) { controller { all } | view { |data| list( model => data ) } }
    end

    # get the given resource for the given model
    path %r{^/#{model}/#{name}/?$}, :method => :get do | model, name |
      resource( model ) { controller { find( name ) } | view { |data| show( model => data ) } }
    end

    # display an editor for the given resource / model
    path %r{^/#{model}/#{name}/editor/?$}, :method => :get do | model, name |
      resource( model ) {  controller { find( name ) } | view { |data| editor( model => data ) } }
    end

  end

end