Class: Bebox::ProfileWizard
- Inherits:
-
Object
- Object
- Bebox::ProfileWizard
- Includes:
- Logger, WizardsHelper
- Defined in:
- lib/bebox/wizards/profile_wizard.rb
Instance Method Summary collapse
-
#create_new_profile(project_root, profile_name, profile_base_path) ⇒ Object
Create a new profile.
-
#list_profiles(project_root) ⇒ Object
Lists existing profiles.
-
#profile_complete_path(profile_base_path, profile_name) ⇒ Object
Create the complete profile path with name.
-
#profile_exists?(project_root, profile_path) ⇒ Boolean
Check if there’s an existing profile in the project.
-
#remove_profile(project_root) ⇒ Object
Removes an existing profile.
Methods included from WizardsHelper
#choose_option, #confirm_action?, #valid_puppet_class_name?, #write_input
Methods included from Logger
#error, #highline_quest, #highline_warn, included, #info, #linebreak, #msg, #ok, #quest, #title, #warn
Instance Method Details
#create_new_profile(project_root, profile_name, profile_base_path) ⇒ Object
Create a new profile
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bebox/wizards/profile_wizard.rb', line 8 def create_new_profile(project_root, profile_name, profile_base_path) # Check if the profile name is valid return error "The profile name can only contain:\n \n* Lowercase letters \n* Numbers \n* Underscores \n* Must begin with an Lowercase letter \n* Can not be any of: #{Bebox::RESERVED_WORDS.join(', ')} \n\nNo changes were made." unless valid_puppet_class_name?(profile_name) unless profile_base_path.empty? # Clean the profile_path to make it a valid path profile_base_path = Bebox::Profile.cleanpath(profile_base_path) # Check if the path name is valid return error "Each part of the path can only contain:\n \n* Lowercase letters \n* Numbers \n* Underscores \n* Must begin with an Lowercase letter \n* Can not be any of: #{Bebox::RESERVED_WORDS.join(', ')} \n\nNo changes were made." unless Bebox::Profile.valid_pathname?(profile_base_path) end # Check if the profile exist profile_path = profile_base_path.empty? ? profile_name : profile_complete_path(profile_base_path, profile_name) return error("The profile '#{profile_path}' already exist. No changes were made.") if profile_exists?(project_root, profile_path) # Profile creation profile = Bebox::Profile.new(profile_name, project_root, profile_base_path) output = profile.create ok "Profile '#{profile_path}' created!." return output end |
#list_profiles(project_root) ⇒ Object
Lists existing profiles
61 62 63 |
# File 'lib/bebox/wizards/profile_wizard.rb', line 61 def list_profiles(project_root) Profile.list(project_root) end |
#profile_complete_path(profile_base_path, profile_name) ⇒ Object
Create the complete profile path with name
66 67 68 |
# File 'lib/bebox/wizards/profile_wizard.rb', line 66 def profile_complete_path(profile_base_path, profile_name) File.join("#{profile_base_path}", "#{profile_name}") end |
#profile_exists?(project_root, profile_path) ⇒ Boolean
Check if there’s an existing profile in the project
71 72 73 |
# File 'lib/bebox/wizards/profile_wizard.rb', line 71 def profile_exists?(project_root, profile_path) Dir.exists?( File.join("#{project_root}/puppet/profiles", "#{profile_path}") ) end |
#remove_profile(project_root) ⇒ Object
Removes an existing profile
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bebox/wizards/profile_wizard.rb', line 40 def remove_profile(project_root) # Choose a profile from the availables profiles = Bebox::Profile.list(project_root) # Get a profile if exist if profiles.count > 0 profile = choose_option(profiles, 'Choose the profile to remove:') else return error "There are no profiles to remove. No changes were made." end # Ask for deletion confirmation return warn('No changes were made.') unless confirm_action?('Are you sure that you want to delete the profile?') # Profile deletion profile_name = profile.split('/').last profile_base_path = profile.split('/')[0...-1].join('/') profile = Bebox::Profile.new(profile_name, project_root, profile_base_path) output = profile.remove ok 'Profile removed!.' return output end |