lib/human_routes/context.rb in human_routes-0.0.1 vs lib/human_routes/context.rb in human_routes-0.0.2
- old
+ new
@@ -8,21 +8,25 @@
def initialize(controller, options = {})
@controller = controller
@options = options
end
+ def controller_name
+ @controller_name ||= options.delete(:name) { controller.to_s }
+ end
+
def singular_controller_name
- @singular_controller_name ||= controller.to_s.singularize
+ @singular_controller_name ||= controller_name.singularize
end
def routes
@routes ||= []
end
def create(*args)
path, name, options = extract_route_args(
- default_path: "#{controller}/new",
+ default_path: "#{controller_name}/new",
default_name: "new_#{singular_controller_name}",
args: args
)
routes << [
@@ -46,11 +50,11 @@
]
end
def update(*args)
path, name, options = extract_route_args(
- default_path: "#{controller}/:id/edit",
+ default_path: "#{controller_name}/:id/edit",
default_name: "edit_#{singular_controller_name}",
args: args
)
routes << [
@@ -74,11 +78,11 @@
]
end
def remove(*args)
path, name, options = extract_route_args(
- default_path: "#{controller}/:id/remove",
+ default_path: "#{controller_name}/:id/remove",
default_name: "remove_#{singular_controller_name}",
args: args
)
routes << [
@@ -102,12 +106,12 @@
]
end
def list(*args)
path, name, options = extract_route_args(
- default_path: controller,
- default_name: controller,
+ default_path: controller_name,
+ default_name: controller_name,
args: args
)
routes << [
path,
@@ -120,10 +124,10 @@
]
end
def show(*args)
path, name, options = extract_route_args(
- default_path: "#{controller}/:id",
+ default_path: "#{controller_name}/:id",
default_name: singular_controller_name,
args: args
)
routes << [