Class: ChefCLI::Policyfile::CookbookLocationSpecification
  
  
  
  
  
    - Inherits:
- 
      Object
      
        
          - Object
- ChefCLI::Policyfile::CookbookLocationSpecification
 show all
      - Includes:
- StorageConfigDelegation
    - Defined in:
- lib/chef-cli/policyfile/cookbook_location_specification.rb
 
  
    
      Constant Summary
      collapse
    
    
      
        - SOURCE_TYPES =
          
        
- i{git github path artifactserver chef_server chef_server_artifact artifactory}.freeze
Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root
  Constructor Details
  
    
  
  
    #initialize(name, version_constraint, source_options, storage_config)  ⇒ CookbookLocationSpecification 
  
  
  
  
    
Returns a new instance of CookbookLocationSpecification.
   
 
  
  
    | 
48
49
50
51
52
53
54 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 48
def initialize(name, version_constraint, source_options, storage_config)
  @name = name
  @version_constraint = Semverse::Constraint.new(version_constraint)
  @source_options = source_options
  @source_type = SOURCE_TYPES.find { |type| source_options.key?(type) }
  @storage_config = storage_config
end
 | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #name  ⇒ Object  
  
  
  
  
    
– Required by CookbookOmnifetch API contract
   
 
  
  
    | 
40
41
42 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 40
def name
  @name
end
 | 
 
    
      
      
      
  
  
    #source_options  ⇒ Object  
  
  
  
  
    
– Required by CookbookOmnifetch API contract
   
 
  
  
    | 
44
45
46 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 44
def source_options
  @source_options
end
 | 
 
    
      
      
      
  
  
    #source_type  ⇒ Object  
  
  
  
  
    
Returns the value of attribute source_type.
   
 
  
  
    | 
45
46
47 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 45
def source_type
  @source_type
end
 | 
 
    
      
      
      
  
  
    #storage_config  ⇒ Object  
  
  
  
  
    
Returns the value of attribute storage_config.
   
 
  
  
    | 
46
47
48 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 46
def storage_config
  @storage_config
end
 | 
 
    
      
      
      
  
  
    #version_constraint  ⇒ Object  
  
  
  
  
    
– Required by CookbookOmnifetch API contract
   
 
  
  
    | 
36
37
38 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 36
def version_constraint
  @version_constraint
end
 | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #==(other)  ⇒ Object 
  
  
  
  
    | 
56
57
58
59
60
61 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 56
def ==(other)
  other.is_a?(self.class) &&
    other.name == name &&
    other.version_constraint == version_constraint &&
    other.source_options == source_options
end
 | 
 
    
      
  
  
    #cache_key  ⇒ Object 
  
  
  
  
    | 
102
103
104 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 102
def cache_key
  installer.cache_key
end
 | 
 
    
      
  
  
    #cached_cookbook  ⇒ Object 
  
  
  
  
    | 
132
133
134
135 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 132
def cached_cookbook
  
  installer.cached_cookbook
end
 | 
 
    
      
  
  
    #cookbook_has_recipe?(recipe_name)  ⇒ Boolean 
  
  
  
  
    | 
126
127
128
129
130 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 126
def cookbook_has_recipe?(recipe_name)
  expected_path = cookbook_path.join("recipes/#{recipe_name}.rb")
  expected_path_yml = cookbook_path.join("recipes/#{recipe_name}.yml")
  expected_path.exist? || expected_path_yml.exist?
end
 | 
 
    
      
  
  
    #cookbook_path  ⇒ Object 
  
  
  
  
    | 
145
146
147
148
149
150
151 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 145
def cookbook_path
  if installer.respond_to?(:expanded_path)
    installer.expanded_path
  else
    installer.install_path.expand_path
  end
end
 | 
 
    
      
  
  
    #dependencies  ⇒ Object 
  
  
  
  
    | 
122
123
124 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 122
def dependencies
  cached_cookbook.dependencies
end
 | 
 
    
      
  
  
    #ensure_cached  ⇒ Object 
  
  
  
  
    | 
79
80
81
82
83 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 79
def ensure_cached
  unless installer.installed?
    installer.install
  end
end
 | 
 
    
      
  
  
    #errors  ⇒ Object 
  
  
  
  
    | 
89
90
91
92
93
94
95 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 89
def errors
  error_messages = []
  if source_options_invalid?
    error_messages << "Cookbook `#{name}' has invalid source options `#{source_options.inspect}'"
  end
  error_messages
end
 | 
 
    
      
  
  
    #installed?  ⇒ Boolean 
  
  
  
  
    | 
75
76
77 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 75
def installed?
  installer.installed?
end
 | 
 
    
      
  
  
    #installer  ⇒ Object 
  
  
  
  
    | 
97
98
99
100 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 97
def installer
  
  @installer ||= CookbookOmnifetch.init(self, source_options)
end
 | 
 
    
      
  
  
    #mirrors_canonical_upstream?  ⇒ Boolean 
  
  
  
  
    | 
71
72
73 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 71
def mirrors_canonical_upstream?
  i{git github artifactserver chef_server chef_server_artifact artifactory}.include?(source_type)
end
 | 
 
    
      
  
  
    #relative_path  ⇒ Object 
  
  
  
  
    | 
106
107
108 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 106
def relative_path
  installer.relative_path.to_s
end
 | 
 
    
      
  
  
    #source_options_for_lock  ⇒ Object 
  
  
  
  
    | 
137
138
139 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 137
def source_options_for_lock
  installer.lock_data
end
 | 
 
    
      
  
  
    #source_options_invalid?  ⇒ Boolean 
  
  
  
  
    | 
141
142
143 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 141
def source_options_invalid?
  !source_options.empty? && installer.nil?
end
 | 
 
    
      
  
  
    #to_s  ⇒ Object 
  
  
  
  
    | 
63
64
65
66
67
68
69 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 63
def to_s
  
  s = "Cookbook '#{name}'"
  s << " #{version_constraint}"
  s << " #{source_options}" unless source_options.empty?
  s
end
 | 
 
    
      
  
  
    #uri  ⇒ Object 
  
  
  
  
    | 
110
111
112 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 110
def uri
  installer.uri
end
 | 
 
    
      
  
  
    #valid?  ⇒ Boolean 
  
  
  
  
    | 
85
86
87 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 85
def valid?
  errors.empty?
end
 | 
 
    
      
  
  
    #version  ⇒ Object 
  
  
  
  
    | 
118
119
120 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 118
def version
  cached_cookbook.version
end
 | 
 
    
      
  
  
    #version_fixed?  ⇒ Boolean 
  
  
  
  
    | 
114
115
116 | # File 'lib/chef-cli/policyfile/cookbook_location_specification.rb', line 114
def version_fixed?
  i{git github path chef_server_artifact}.include?(@source_type)
end
 |