Class: Chef::TidyCommon
- Inherits:
-
Object
- Object
- Chef::TidyCommon
- Defined in:
- lib/chef/tidy_common.rb
Instance Attribute Summary collapse
-
#backup_path ⇒ Object
Returns the value of attribute backup_path.
Instance Method Summary collapse
- #clients_path(org) ⇒ Object
- #cookbook_name_from_path(path) ⇒ Object
- #cookbooks_path(org) ⇒ Object
- #global_user_names ⇒ Object
- #groups_path(org) ⇒ Object
-
#initialize(backup_path = Dir.pwd) ⇒ TidyCommon
constructor
A new instance of TidyCommon.
- #members_path(org) ⇒ Object
- #org_acls_path(org) ⇒ Object
- #org_path(org) ⇒ Object
- #reports_dir ⇒ Object
- #save_user(user) ⇒ Object
- #unique_email ⇒ Object
- #user_acls_path ⇒ Object
- #users_path ⇒ Object
- #write_new_file(contents, path) ⇒ Object
Constructor Details
#initialize(backup_path = Dir.pwd) ⇒ TidyCommon
Returns a new instance of TidyCommon.
8 9 10 |
# File 'lib/chef/tidy_common.rb', line 8 def initialize(backup_path = Dir.pwd) @backup_path = ::File.(backup_path) end |
Instance Attribute Details
#backup_path ⇒ Object
Returns the value of attribute backup_path.
6 7 8 |
# File 'lib/chef/tidy_common.rb', line 6 def backup_path @backup_path end |
Instance Method Details
#clients_path(org) ⇒ Object
20 21 22 |
# File 'lib/chef/tidy_common.rb', line 20 def clients_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'clients')) end |
#cookbook_name_from_path(path) ⇒ Object
64 65 66 |
# File 'lib/chef/tidy_common.rb', line 64 def cookbook_name_from_path(path) ::File.basename(path, '-*') end |
#cookbooks_path(org) ⇒ Object
36 37 38 |
# File 'lib/chef/tidy_common.rb', line 36 def cookbooks_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'cookbooks')) end |
#global_user_names ⇒ Object
68 69 70 |
# File 'lib/chef/tidy_common.rb', line 68 def global_user_names @global_user_names ||= Dir[::File.join(@backup_path, 'users', '*')].map { |dir| ::File.basename(dir, '.json') } end |
#groups_path(org) ⇒ Object
24 25 26 |
# File 'lib/chef/tidy_common.rb', line 24 def groups_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'groups')) end |
#members_path(org) ⇒ Object
16 17 18 |
# File 'lib/chef/tidy_common.rb', line 16 def members_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'members.json')) end |
#org_acls_path(org) ⇒ Object
28 29 30 |
# File 'lib/chef/tidy_common.rb', line 28 def org_acls_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'acls')) end |
#org_path(org) ⇒ Object
40 41 42 |
# File 'lib/chef/tidy_common.rb', line 40 def org_path(org) ::File.(::File.join(@backup_path, 'organizations', org)) end |
#reports_dir ⇒ Object
72 73 74 |
# File 'lib/chef/tidy_common.rb', line 72 def reports_dir @reports_dir ||= ::File.join(Dir.pwd, 'reports') end |
#save_user(user) ⇒ Object
49 50 51 52 53 |
# File 'lib/chef/tidy_common.rb', line 49 def save_user(user) ::File.open(::File.join(users_path, "#{user['username']}.json"), 'w+') do |f| f.write(FFI_Yajl::Encoder.encode(user, pretty: true)) end end |
#unique_email ⇒ Object
44 45 46 47 |
# File 'lib/chef/tidy_common.rb', line 44 def unique_email (0...8).map { (65 + rand(26)).chr }.join.downcase + '@' + (0...8).map { (65 + rand(26)).chr }.join.downcase + '.com' end |
#user_acls_path ⇒ Object
32 33 34 |
# File 'lib/chef/tidy_common.rb', line 32 def user_acls_path @user_acls_path ||= ::File.(::File.join(@backup_path, 'user_acls')) end |
#users_path ⇒ Object
12 13 14 |
# File 'lib/chef/tidy_common.rb', line 12 def users_path @users_path ||= ::File.(::File.join(@backup_path, 'users')) end |
#write_new_file(contents, path) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/chef/tidy_common.rb', line 55 def write_new_file(contents, path) if ::File.exist?(path) FileUtils.cp(path, "#{path}.orig") unless ::File.exist?("#{path}.orig") end ::File.open(path, 'w+') do |f| f.write(FFI_Yajl::Encoder.encode(contents, pretty: true)) end end |