Skip to content

Instantly share code, notes, and snippets.

@nmeans
Last active August 26, 2016 15:11
Show Gist options
  • Save nmeans/611b3decb8945a44363dd5968c45f3f5 to your computer and use it in GitHub Desktop.
Save nmeans/611b3decb8945a44363dd5968c45f3f5 to your computer and use it in GitHub Desktop.
def parse_roles(user_hash)
custom_schemas = user_hash.fetch("customSchemas") { return [] }
roles = custom_schemas.fetch("Roles") { return [] }
roles
end
user1 = {
"email": "andrew@muvehealthlabs.com",
"customSchemas": {
"Roles": ["accountant", "admin"]
}
}
parse_roles(user1)
# ["accountant", "admin"]
user2 = {
"email": "nick@muvehealthlabs.com"
}
parse_roles(user2)
# []
user3 = {
"email": "peter@muvehealthlabs.com"
"customSchemas": {
"Title": "Docker Jesus"
}
}
parse_roles(user3)
# []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment