Class: ChefCLI::Policyfile::StorageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/policyfile/storage_config.rb

Overview

Provides handling of relative paths, such as on disk cookbooks which are specified relative to the Policyfile and local caching of compiled Policyfile artifacts.

Author:

  • Dan DeLeo

Since:

  • 0.11.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StorageConfig

Returns a new instance of StorageConfig.

Since:

  • 0.11.0



42
43
44
45
46
47
48
# File 'lib/chef-cli/policyfile/storage_config.rb', line 42

def initialize(options = {})
  @relative_paths_root = Dir.pwd
  @cache_path = CookbookOmnifetch.storage_path
  @policyfile_filename = "<< Policyfile filename not specified >>"
  @policyfile_lock_filename = "<< Policyfile lock filename not specified >>"
  handle_options(options)
end

Instance Attribute Details

#cache_pathObject

Since:

  • 0.11.0



37
38
39
# File 'lib/chef-cli/policyfile/storage_config.rb', line 37

def cache_path
  @cache_path
end

#policyfile_filenameString (readonly)

Uncompiled Policyfile filename.

Returns:

  • (String)

    the current value of policyfile_filename

Since:

  • 0.11.0



34
35
36
# File 'lib/chef-cli/policyfile/storage_config.rb', line 34

def policyfile_filename
  @policyfile_filename
end

#policyfile_lock_filenameString (readonly)

Filename of compiled Policyfile.

Returns:

  • (String)

    the current value of policyfile_lock_filename

Since:

  • 0.11.0



34
35
36
# File 'lib/chef-cli/policyfile/storage_config.rb', line 34

def policyfile_lock_filename
  @policyfile_lock_filename
end

#relative_paths_rootObject

Since:

  • 0.11.0



36
37
38
# File 'lib/chef-cli/policyfile/storage_config.rb', line 36

def relative_paths_root
  @relative_paths_root
end

Instance Method Details

#policyfile_expanded_pathObject

Since:

  • 0.11.0



71
72
73
# File 'lib/chef-cli/policyfile/storage_config.rb', line 71

def policyfile_expanded_path
  File.expand_path(policyfile_filename, relative_paths_root)
end

#policyfile_lock_expanded_pathObject

Since:

  • 0.11.0



75
76
77
# File 'lib/chef-cli/policyfile/storage_config.rb', line 75

def policyfile_lock_expanded_path
  File.expand_path(policyfile_lock_filename, relative_paths_root)
end

#use_policyfile(policyfile_filename) ⇒ Object

Since:

  • 0.11.0



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/chef-cli/policyfile/storage_config.rb', line 50

def use_policyfile(policyfile_filename)
  if policyfile_filename.end_with?(".lock.json")
    return use_policyfile_lock(policyfile_filename)
  end
  unless policyfile_filename.end_with?(".rb")
    raise InvalidPolicyfileFilename, "Policyfile filenames must end with an `.rb' or `.lock.json' extension (you gave: `#{policyfile_filename}')"
  end

  @policyfile_filename = policyfile_filename
  @policyfile_lock_filename = policyfile_filename.sub(/\.rb\Z/, ".lock.json")
  @relative_paths_root = File.dirname(policyfile_filename)
  self
end

#use_policyfile_lock(policyfile_lock_filename) ⇒ Object

Since:

  • 0.11.0



64
65
66
67
68
69
# File 'lib/chef-cli/policyfile/storage_config.rb', line 64

def use_policyfile_lock(policyfile_lock_filename)
  @policyfile_lock_filename = policyfile_lock_filename
  @policyfile_filename = policyfile_lock_filename.sub(/\.lock\.json\Z/, ".rb")
  @relative_paths_root = File.dirname(policyfile_lock_filename)
  self
end