Class: ChefCLI::PolicyfileServices::ExportRepo
- Inherits:
-
Object
- Object
- ChefCLI::PolicyfileServices::ExportRepo
- Defined in:
- lib/chef-cli/policyfile_services/export_repo.rb
Instance Attribute Summary collapse
-
#export_dir ⇒ Object
readonly
Returns the value of attribute export_dir.
-
#policy_group ⇒ Object
readonly
Returns the value of attribute policy_group.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#storage_config ⇒ Object
readonly
Returns the value of attribute storage_config.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Instance Method Summary collapse
- #archive? ⇒ Boolean
- #archive_file_location ⇒ Object
- #export ⇒ Object
-
#initialize(policyfile: nil, export_dir: nil, root_dir: nil, archive: false, force: false, policy_group: nil) ⇒ ExportRepo
constructor
A new instance of ExportRepo.
- #policy_data ⇒ Object
- #policy_name ⇒ Object
- #policyfile_lock ⇒ Object
- #run ⇒ Object
Methods included from ChefCLI::Policyfile::StorageConfigDelegation
#cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root
Constructor Details
#initialize(policyfile: nil, export_dir: nil, root_dir: nil, archive: false, force: false, policy_group: nil) ⇒ ExportRepo
Returns a new instance of ExportRepo.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 44 def initialize(policyfile: nil, export_dir: nil, root_dir: nil, archive: false, force: false, policy_group: nil) @root_dir = root_dir @export_dir = File.(export_dir) @archive = archive @force_export = force @ui = UI.new @policy_data = nil @policyfile_lock = nil @policy_group = policy_group @policy_group ||= "local".freeze policyfile_rel_path = policyfile || "Policyfile.rb" policyfile_full_path = File.(policyfile_rel_path, root_dir) @storage_config = Policyfile::StorageConfig.new.use_policyfile(policyfile_full_path) @staging_dir = nil end |
Instance Attribute Details
#export_dir ⇒ Object (readonly)
Returns the value of attribute export_dir.
40 41 42 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 40 def export_dir @export_dir end |
#policy_group ⇒ Object (readonly)
Returns the value of attribute policy_group.
42 43 44 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 42 def policy_group @policy_group end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
39 40 41 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 39 def root_dir @root_dir end |
#storage_config ⇒ Object (readonly)
Returns the value of attribute storage_config.
38 39 40 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 38 def storage_config @storage_config end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
41 42 43 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 41 def ui @ui end |
Instance Method Details
#archive? ⇒ Boolean
63 64 65 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 63 def archive? @archive end |
#archive_file_location ⇒ Object
90 91 92 93 94 95 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 90 def archive_file_location return nil unless archive? filename = "#{policyfile_lock.name}-#{policyfile_lock.revision_id}.tgz" File.join(export_dir, filename) end |
#export ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 97 def export with_staging_dir do create_repo_structure copy_cookbooks create_policyfile_repo_item create_policy_group_repo_item copy_policyfile_lock create_client_rb create_readme_md if archive? create_archive else mv_staged_repo end end rescue => error msg = "Failed to export policy (in #{policyfile_filename}) to #{export_dir}" raise PolicyfileExportRepoError.new(msg, error) end |
#policy_data ⇒ Object
80 81 82 83 84 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 80 def policy_data @policy_data ||= FFI_Yajl::Parser.parse(IO.read()) rescue => error raise PolicyfileExportRepoError.new("Error reading lockfile #{}", error) end |
#policy_name ⇒ Object
67 68 69 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 67 def policy_name policyfile_lock.name end |
#policyfile_lock ⇒ Object
86 87 88 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 86 def policyfile_lock @policyfile_lock || validate_lockfile end |
#run ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/chef-cli/policyfile_services/export_repo.rb', line 71 def run assert_lockfile_exists! assert_export_dir_clean! validate_lockfile write_updated_lockfile export end |