From 0209f73d9db89ca6efdb4bbafbaee6d091290d69 Mon Sep 17 00:00:00 2001 From: Spencer Alan Date: Wed, 19 Dec 2018 17:21:19 -0500 Subject: [PATCH] add comments to the recursive methods to help provide more clarity --- app/controllers/concerns/scim_rails/response.rb | 8 ++++++++ app/controllers/scim_rails/scim_users_controller.rb | 8 ++++++++ 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/app/controllers/concerns/scim_rails/response.rb b/app/controllers/concerns/scim_rails/response.rb index bdae626..fc622f8 100644 --- a/app/controllers/concerns/scim_rails/response.rb +++ b/app/controllers/concerns/scim_rails/response.rb @@ -53,6 +53,14 @@ module ScimRails find_value(user, schema) end + + # `find_value` is a recursive method that takes a "user" and a + # "user schema" and replaces any symbols in the schema with the + # corresponding value from the user. Given a schema with symbols, + # `find_value` will search through the object for the symbols, + # send those symbols to the model, and replace the symbol with + # the return value. + def find_value(user, object) case object when Hash diff --git a/app/controllers/scim_rails/scim_users_controller.rb b/app/controllers/scim_rails/scim_users_controller.rb index de89634..68ae776 100644 --- a/app/controllers/scim_rails/scim_users_controller.rb +++ b/app/controllers/scim_rails/scim_users_controller.rb @@ -71,6 +71,14 @@ module ScimRails params.dig(*path_for(attribute)) end + # `path_for` is a recursive method used to find the "path" for + # `.dig` to take when looking for a given attribute in the + # params. + # + # Example: `path_for(:name)` should return an array that looks + # like [:names, 0, :givenName]. `.dig` can then use that path + # against the params to translate the :name attribute to "John". + def path_for(attribute, object = ScimRails.config.mutable_user_attributes_schema, path = []) at_path = path.empty? ? object : object.dig(*path) return path if at_path == attribute -- libgit2 0.21.0