Class: ChefDK::Policyfile::CookbookSpec

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version_constraint, source_options, policyfile_filename) ⇒ CookbookSpec

Returns a new instance of CookbookSpec.



33
34
35
36
37
38
39
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 33

def initialize(name, version_constraint, source_options, policyfile_filename)
  @name = name
  @version_constraint = Semverse::Constraint.new(version_constraint)
  @source_options = source_options
  @policyfile_filename = policyfile_filename
  @source_type = SOURCE_TYPES.find { |type| source_options.key?(type) }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 29

def name
  @name
end

#source_optionsObject (readonly)

Returns the value of attribute source_options.



30
31
32
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 30

def source_options
  @source_options
end

#source_typeObject (readonly)

Returns the value of attribute source_type.



31
32
33
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 31

def source_type
  @source_type
end

#version_constraintObject (readonly)

Returns the value of attribute version_constraint.



28
29
30
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 28

def version_constraint
  @version_constraint
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
44
45
46
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 41

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



62
63
64
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 62

def cache_key
  installer.cache_key
end

#cached_cookbookObject



86
87
88
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 86

def cached_cookbook
  installer.cached_cookbook
end

#dependenciesObject



82
83
84
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 82

def dependencies
  cached_cookbook.dependencies
end

#ensure_cachedObject



52
53
54
55
56
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 52

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

#installerObject



58
59
60
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 58

def installer
  @installer ||= CookbookOmnifetch.init(self, source_options)
end

#mirrors_canonical_upstream?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 48

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

#relative_pathObject



66
67
68
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 66

def relative_path
  installer.relative_path.to_s
end

#relative_paths_rootObject



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

def relative_paths_root
  File.dirname(@policyfile_filename)
end

#uriObject



70
71
72
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 70

def uri
  installer.uri
end

#versionObject



78
79
80
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 78

def version
  cached_cookbook.version
end

#version_fixed?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/chef-dk/policyfile/cookbook_spec.rb', line 74

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