Class: ChefDK::Policyfile::CookbookLocationSpecification

Inherits:
Object
  • Object
show all
Includes:
StorageConfigDelegation
Defined in:
lib/chef-dk/policyfile/cookbook_location_specification.rb

Constant Summary collapse

SOURCE_TYPES =
[:git, :github, :path, :artifactserver]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StorageConfigDelegation

#cache_path, #policyfile_filename, #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-dk/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

#nameObject (readonly)

– Required by CookbookOmnifetch API contract



40
41
42
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 40

def name
  @name
end

#source_optionsObject (readonly)

– Required by CookbookOmnifetch API contract



44
45
46
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 44

def source_options
  @source_options
end

#source_typeObject (readonly)

Returns the value of attribute source_type.



45
46
47
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 45

def source_type
  @source_type
end

#storage_configObject (readonly)

Returns the value of attribute storage_config.



46
47
48
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 46

def storage_config
  @storage_config
end

#version_constraintObject (readonly)

– Required by CookbookOmnifetch API contract



36
37
38
# File 'lib/chef-dk/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-dk/policyfile/cookbook_location_specification.rb', line 56

def ==(other)
  other.kind_of?(self.class) and
    other.name == name and
    other.version_constraint == version_constraint and
    other.source_options == source_options
end

#cache_keyObject



94
95
96
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 94

def cache_key
  installer.cache_key
end

#cached_cookbookObject



118
119
120
121
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 118

def cached_cookbook
  # TODO: handle 'bad' return values here (cookbook not installed yet)
  installer.cached_cookbook
end

#dependenciesObject



114
115
116
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 114

def dependencies
  cached_cookbook.dependencies
end

#ensure_cachedObject



71
72
73
74
75
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 71

def ensure_cached
  unless installer.installed?
    installer.install
  end
end

#errorsObject



81
82
83
84
85
86
87
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 81

def errors
  error_messages = []
  if installer.nil?
    error_messages << "Cookbook `#{name}' has invalid source options `#{source_options.inspect}'"
  end
  error_messages
end

#installed?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 67

def installed?
  installer.installed?
end

#installerObject



89
90
91
92
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 89

def installer
  # TODO: handle 'bad' return values here (invalid source_options, etc.)
  @installer ||= CookbookOmnifetch.init(self, source_options)
end

#mirrors_canonical_upstream?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 63

def mirrors_canonical_upstream?
  [:git, :github, :artifactserver].include?(source_type)
end

#relative_pathObject



98
99
100
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 98

def relative_path
  installer.relative_path.to_s
end

#source_options_for_lockObject



123
124
125
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 123

def source_options_for_lock
  installer.lock_data
end

#uriObject



102
103
104
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 102

def uri
  installer.uri
end

#valid?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 77

def valid?
  errors.empty?
end

#versionObject



110
111
112
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 110

def version
  cached_cookbook.version
end

#version_fixed?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/chef-dk/policyfile/cookbook_location_specification.rb', line 106

def version_fixed?
  [:git, :github, :path].include?(@source_type)
end