Commit 0209f73d9db89ca6efdb4bbafbaee6d091290d69
1 parent
64243d0d
Exists in
master
add comments to the recursive methods to help provide more clarity
Showing
2 changed files
with
16 additions
and
0 deletions
Show diff stats
app/controllers/concerns/scim_rails/response.rb
@@ -53,6 +53,14 @@ module ScimRails | @@ -53,6 +53,14 @@ module ScimRails | ||
53 | find_value(user, schema) | 53 | find_value(user, schema) |
54 | end | 54 | end |
55 | 55 | ||
56 | + | ||
57 | + # `find_value` is a recursive method that takes a "user" and a | ||
58 | + # "user schema" and replaces any symbols in the schema with the | ||
59 | + # corresponding value from the user. Given a schema with symbols, | ||
60 | + # `find_value` will search through the object for the symbols, | ||
61 | + # send those symbols to the model, and replace the symbol with | ||
62 | + # the return value. | ||
63 | + | ||
56 | def find_value(user, object) | 64 | def find_value(user, object) |
57 | case object | 65 | case object |
58 | when Hash | 66 | when Hash |
app/controllers/scim_rails/scim_users_controller.rb
@@ -71,6 +71,14 @@ module ScimRails | @@ -71,6 +71,14 @@ module ScimRails | ||
71 | params.dig(*path_for(attribute)) | 71 | params.dig(*path_for(attribute)) |
72 | end | 72 | end |
73 | 73 | ||
74 | + # `path_for` is a recursive method used to find the "path" for | ||
75 | + # `.dig` to take when looking for a given attribute in the | ||
76 | + # params. | ||
77 | + # | ||
78 | + # Example: `path_for(:name)` should return an array that looks | ||
79 | + # like [:names, 0, :givenName]. `.dig` can then use that path | ||
80 | + # against the params to translate the :name attribute to "John". | ||
81 | + | ||
74 | def path_for(attribute, object = ScimRails.config.mutable_user_attributes_schema, path = []) | 82 | def path_for(attribute, object = ScimRails.config.mutable_user_attributes_schema, path = []) |
75 | at_path = path.empty? ? object : object.dig(*path) | 83 | at_path = path.empty? ? object : object.dig(*path) |
76 | return path if at_path == attribute | 84 | return path if at_path == attribute |