Function: projectile--rails-resource-key

projectile--rails-resource-key is a byte-compiled function defined in projectile.el.

Signature

(projectile--rails-resource-key REL-PATH PREFIX SUFFIX)

Documentation

Return the namespaced singular Rails resource key of REL-PATH.

PREFIX is the resource root (e.g. "app/controllers/") and SUFFIX the file suffix (e.g. "_controller.rb"). Rails names controllers, helpers and views after the *plural* resource (e.g. "users_controller.rb"), while models use the singular ("user.rb"); singularizing the stripped name makes them share the model's key. Any namespace directories under PREFIX are preserved, so "app/controllers/admin/users_controller.rb" keys as "admin/user" and does not collide with a top-level
"users_controller.rb". The singularizer is naive (see
projectile--singularize), so irregular resource names will not relate correctly.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
;;;; Reference file-kinds tables (Rails, Django)

(defun projectile--rails-resource-key (rel-path prefix suffix)
  "Return the namespaced singular Rails resource key of REL-PATH.
PREFIX is the resource root (e.g. \"app/controllers/\") and SUFFIX the
file suffix (e.g. \"_controller.rb\").  Rails names controllers, helpers
and views after the *plural* resource (e.g. \"users_controller.rb\"),
while models use the singular (\"user.rb\"); singularizing the stripped
name makes them share the model's key.  Any namespace directories under
PREFIX are preserved, so \"app/controllers/admin/users_controller.rb\"
keys as \"admin/user\" and does not collide with a top-level
\"users_controller.rb\".  The singularizer is naive (see
`projectile--singularize'), so irregular resource names will not relate
correctly."
  (when (and (string-prefix-p prefix rel-path)
             (string-suffix-p suffix (file-name-nondirectory rel-path)))
    (let* ((subpath (substring rel-path (length prefix)))
           (dir (or (file-name-directory subpath) ""))
           (base (file-name-nondirectory subpath))
           (resource (substring base 0 (- (length suffix)))))
      (concat dir (projectile--singularize resource)))))