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}/

Instance Method Summary collapse

Instance Method Details

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

Creates default routes



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

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



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

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



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

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

Since:

  • 0.0.1



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

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



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

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