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.
- #invitations_path(org) ⇒ Object
- #members_path(org) ⇒ Object
- #org_acls_path(org) ⇒ Object
- #org_path(org) ⇒ Object
- #reports_dir ⇒ Object
- #roles_path(org) ⇒ 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 11 12 |
# File 'lib/chef/tidy_common.rb', line 8 def initialize(backup_path = Dir.pwd) Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 @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
26 27 28 |
# File 'lib/chef/tidy_common.rb', line 26 def clients_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'clients')) end |
#cookbook_name_from_path(path) ⇒ Object
74 75 76 |
# File 'lib/chef/tidy_common.rb', line 74 def cookbook_name_from_path(path) ::File.basename(path, '-*') end |
#cookbooks_path(org) ⇒ Object
42 43 44 |
# File 'lib/chef/tidy_common.rb', line 42 def cookbooks_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'cookbooks')) end |
#global_user_names ⇒ Object
78 79 80 |
# File 'lib/chef/tidy_common.rb', line 78 def global_user_names @global_user_names ||= Dir[::File.join(@backup_path, 'users', '*')].map { |dir| ::File.basename(dir, '.json') } end |
#groups_path(org) ⇒ Object
30 31 32 |
# File 'lib/chef/tidy_common.rb', line 30 def groups_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'groups')) end |
#invitations_path(org) ⇒ Object
22 23 24 |
# File 'lib/chef/tidy_common.rb', line 22 def invitations_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'invitations.json')) end |
#members_path(org) ⇒ Object
18 19 20 |
# File 'lib/chef/tidy_common.rb', line 18 def members_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'members.json')) end |
#org_acls_path(org) ⇒ Object
34 35 36 |
# File 'lib/chef/tidy_common.rb', line 34 def org_acls_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'acls')) end |
#org_path(org) ⇒ Object
50 51 52 |
# File 'lib/chef/tidy_common.rb', line 50 def org_path(org) ::File.(::File.join(@backup_path, 'organizations', org)) end |
#reports_dir ⇒ Object
82 83 84 |
# File 'lib/chef/tidy_common.rb', line 82 def reports_dir @reports_dir ||= ::File.join(Dir.pwd, 'reports') end |
#roles_path(org) ⇒ Object
46 47 48 |
# File 'lib/chef/tidy_common.rb', line 46 def roles_path(org) ::File.(::File.join(@backup_path, 'organizations', org, 'roles')) end |
#save_user(user) ⇒ Object
59 60 61 62 63 |
# File 'lib/chef/tidy_common.rb', line 59 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
54 55 56 57 |
# File 'lib/chef/tidy_common.rb', line 54 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
38 39 40 |
# File 'lib/chef/tidy_common.rb', line 38 def user_acls_path @user_acls_path ||= ::File.(::File.join(@backup_path, 'user_acls')) end |
#users_path ⇒ Object
14 15 16 |
# File 'lib/chef/tidy_common.rb', line 14 def users_path @users_path ||= ::File.(::File.join(@backup_path, 'users')) end |
#write_new_file(contents, path) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/chef/tidy_common.rb', line 65 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 |