diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-09-26 22:22:29 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-09-26 22:22:29 -0700 |
commit | 8400f4cb7d977896531ae277fdcf3398dc2d4c6c (patch) | |
tree | 33b8b5ba385366457de4990636daa143d64f1043 /lib/chef/user.rb | |
parent | 8daa1c6598182777802eba6a74928f28a32f6835 (diff) | |
download | chef-8400f4cb7d977896531ae277fdcf3398dc2d4c6c.tar.gz |
replace some instances of to_hash with to_hlcg/to-h-cleanup
to_hash on a lot of these objects should go away, but even eliminating
all our calls to to_hash on these objects internally is difficult.
(e.g. converting the knife ui code to call #to_h means we wind up
calling nil#to_h which "helpfully" becomes '{}' which is hilarious and
i don't know why someone thought that was a good idea).
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/user.rb')
-rw-r--r-- | lib/chef/user.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/chef/user.rb b/lib/chef/user.rb index eba55c4186..f44d38c2d5 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -1,6 +1,6 @@ # # Author:: Steven Danna (steve@chef.io) -# Copyright:: Copyright 2012-2016, Chef Software, Inc. +# Copyright:: Copyright 2012-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -77,7 +77,7 @@ class Chef arg, kind_of: String) end - def to_hash + def to_h result = { "name" => @name, "public_key" => @public_key, @@ -88,8 +88,10 @@ class Chef result end + alias_method :to_hash, :to_h + def to_json(*a) - Chef::JSONCompat.to_json(to_hash, *a) + Chef::JSONCompat.to_json(to_h, *a) end def destroy @@ -100,7 +102,7 @@ class Chef payload = { name: name, admin: admin, password: password } payload[:public_key] = public_key if public_key new_user = chef_rest_v0.post("users", payload) - Chef::User.from_hash(to_hash.merge(new_user)) + Chef::User.from_hash(to_h.merge(new_user)) end def update(new_key = false) @@ -108,7 +110,7 @@ class Chef payload[:private_key] = new_key if new_key payload[:password] = password if password updated_user = chef_rest_v0.put("users/#{name}", payload) - Chef::User.from_hash(to_hash.merge(updated_user)) + Chef::User.from_hash(to_h.merge(updated_user)) end def save(new_key = false) |