Class: Umlaut::Routes

Inherits:
Object
  • Object
show all
Includes:
RouteSets
Defined in:
lib/umlaut/routes.rb

Overview

Class to inject Umlaut routes, design copied from Blacklight project. you would do a:

Umlaut::Routes.new(self, optional_args).draw

in local app routes.rb, that line is generated into local app by Umlaut generator. options include :only and :except to limit what route groups are generated.

Defined Under Namespace

Modules: RouteSets

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RouteSets

#a_z, #admin, #export_email, #feedback, #javascript, #link_router, #open_search, #permalinks, #resolve, #resources, #root, #search

Constructor Details

#initialize(router, options = {}) ⇒ Routes

Returns a new instance of Routes.



13
14
15
16
# File 'lib/umlaut/routes.rb', line 13

def initialize(router, options ={})
  @router = router
  @options = options
end

Class Method Details

.register_routes(module_obj, route_set_methods = nil) ⇒ Object

Experimental functionality for a plugin to add routes that automatically will get applied by Umlaut::Routes

Umlaut::Routes.register_routes( YourPlugin::RouteSets )

Where YourPlugin::RouteSets is a module containing methods that defines routes similar to Umlaut::Routes::RouteSets below.

If some methods included in the module are not route-defining methods, pass a second arg listing just those that are:

Umlaut::Routes.register_routes(YourPlugin::RouteSets, [:magic, :underwater])

All route_set_methods will be applied by default, but can be excluded on application with the standard Umlaut::RouteSet :only and :except args.

This design is somewhat experimental, we’ll see if it meets real world use cases with maintainable code.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/umlaut/routes.rb', line 43

def self.register_routes(module_obj, route_set_methods = nil)
  if route_set_methods.nil?
    # default to all methods defined in module
    route_set_methods = module_obj.instance_methods
  end

  include module_obj
  self.default_route_sets.concat route_set_methods

  return self
end

Instance Method Details

#drawObject



18
19
20
21
22
# File 'lib/umlaut/routes.rb', line 18

def draw
  route_sets.each do |r|
    self.send(r)
  end
end