lib/hanami/routing/resources/action.rb in hanami-router-1.3.2 vs lib/hanami/routing/resources/action.rb in hanami-router-2.0.0.alpha1
- old
+ new
@@ -1,9 +1,10 @@
-require 'hanami/utils/string'
-require 'hanami/utils/path_prefix'
-require 'hanami/routing/resource'
+# frozen_string_literal: true
+require "hanami/utils/path_prefix"
+require "hanami/routing/resource"
+
module Hanami
module Routing
class Resources < Resource
# Action for RESTful resources
#
@@ -22,25 +23,26 @@
# Id route variable
#
# @since 0.2.0
# @api private
class_attribute :identifier
- self.identifier = ':id'.freeze
+ self.identifier = ":id"
end
# Pluralize concrete actions
#
# @api private
# @since 0.4.0
module PluralizedAction
private
+
# The name of the RESTful action.
#
# @api private
# @since 0.4.0
def as
- Hanami::Utils::String.pluralize(super)
+ @router.inflector.pluralize(super).to_sym
end
end
# Collection action
# It implements #collection within a #resources block.
@@ -48,11 +50,11 @@
# @api private
# @since 0.1.0
# @see Hanami::Router#resources
class CollectionAction < Resource::CollectionAction
def as(action_name)
- Hanami::Utils::String.pluralize(super(action_name))
+ @router.inflector.pluralize(super(action_name)).to_sym
end
end
# Member action
# It implements #member within a #resources block.
@@ -60,10 +62,11 @@
# @api private
# @since 0.1.0
# @see Hanami::Router#resources
class MemberAction < Resource::MemberAction
private
+
# @since 0.1.0
# @api private
def path(action_name)
rest_path.join(Action.identifier, action_name)
end
@@ -73,10 +76,11 @@
#
# @api private
# @since 0.1.0
module DefaultMemberAction
private
+
# @since 0.1.0
# @api private
def path
rest_path.join(Action.identifier)
end
@@ -125,9 +129,10 @@
# @see Hanami::Router#resources
class Edit < Resource::Edit
include DefaultMemberAction
private
+
# @since 0.1.0
# @api private
def path
super.join(action_name)
end