Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
app/lib/ext/action_dispatch/routing/mapper.rb

Constant Summary collapse

ID_FORMAT_REGEX =

Mapper class provides methods for routes.rb

/\w{8}/
ID_OR_SCHEMA_FORMAT_REGEX =
/\w{8}|schema\/\w+/

Instance Method Summary collapse

Instance Method Details

#build_default_routes(route_name, current: true, lookup: true, postcode: true) ⇒ Object

Creates default routes

Parameters:

  • route_name (String)

    multiple base routes.

  • current (Boolean) (defaults to: true)

    indicates whether to use only current (defaults to true).

  • lookup (Boolean) (defaults to: true)

    indicates whether to use lookup (defaults to true).

  • postcode (Boolean) (defaults to: true)

    indicates whether to use postcode (defaults to true).



37
38
39
40
41
42
# File 'app/lib/ext/action_dispatch/routing/mapper.rb', line 37

def build_default_routes(route_name, current: true, lookup: true, postcode: true)
  get '/', to: "#{route_name}#index"
  get '/current', to: "#{route_name}#current" if current
  get '/lookup', to: "#{route_name}#lookup" if lookup
  post '/postcode_lookup', to: "#{route_name}#postcode_lookup", as: 'postcode_lookup' if postcode
end

#build_members_routes(route_name, current: true) ⇒ Object

Creates members routes

Parameters:

  • route_name (String)

    members route.

  • current (Boolean) (defaults to: true)

    indicates whether to use current (defaults to true).



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/lib/ext/action_dispatch/routing/mapper.rb', line 59

def build_members_routes(route_name, current: true)
  scope '/members', as: 'members' do
    get '/', to: "#{route_name}#index"

    listable("#{route_name}#a_to_z", "#{route_name}#letters")

    scope '/current', as: 'current' do # /route_name/:id/members/current
      if current
        get '/', to: "#{route_name}#current"

        listable("#{route_name}#a_to_z_current", "#{route_name}#current_letters")
      end
    end

    yield if block_given?
  end
end

#build_root_and_current_routes(parent_route_name, route_name) ⇒ Object

Creates base routes and current routes

Parameters:

  • parent_route_name (String)

    parent route.

  • route_name (String)

    current route.



48
49
50
51
52
53
# File 'app/lib/ext/action_dispatch/routing/mapper.rb', line 48

def build_root_and_current_routes(parent_route_name, route_name)
  scope "/#{route_name}", as: route_name do
    get '/',        to: "#{parent_route_name}#index"
    get '/current', to: "#{parent_route_name}#current"
  end
end

#listable(a_z_action, letter_action) ⇒ Object

Creates routes for listables

Parameters:

  • a_z_action (String)

    a to z route.

  • letter_action (String)

    letter route.

Since:

  • 0.0.1



13
14
15
16
17
18
19
20
21
# File 'app/lib/ext/action_dispatch/routing/mapper.rb', line 13

def listable(a_z_action, letter_action)
  scope '/a-z', as: 'a_z' do
    get '/',    to: a_z_action

    scope '/:letter', as: 'letter' do
      get '/', to: letter_action
    end
  end
end

#lookupable(action) ⇒ Object

Creates routes for lookupable

Parameters:

  • action (String)

    lookup by letter route.



26
27
28
# File 'app/lib/ext/action_dispatch/routing/mapper.rb', line 26

def lookupable(action)
  get '/:letters', to: action
end