Class: ChefDK::PolicyfileLock::LocalCookbook

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

Overview

LocalCookbook objects represent cookbooks that are sourced from the local filesystem and are assumed to be under active development.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, relative_paths_root) ⇒ LocalCookbook

Returns a new instance of LocalCookbook.



119
120
121
122
123
# File 'lib/chef-dk/policyfile_lock.rb', line 119

def initialize(name, relative_paths_root)
  @name = name
  @identifier = nil
  @relative_paths_root = relative_paths_root
end

Instance Attribute Details

#dotted_decimal_identifierObject



141
142
143
# File 'lib/chef-dk/policyfile_lock.rb', line 141

def dotted_decimal_identifier
  @dotted_decimal_identifier || identifiers.dotted_decimal_identifier
end

#identifierObject



137
138
139
# File 'lib/chef-dk/policyfile_lock.rb', line 137

def identifier
  @identifier || identifiers.content_identifier
end

#relative_paths_rootObject

The root path from which source is expanded.



117
118
119
# File 'lib/chef-dk/policyfile_lock.rb', line 117

def relative_paths_root
  @relative_paths_root
end

#sourceObject

A relative or absolute path to the cookbook. If a relative path is given, it is resolved relative to #relative_paths_root



104
105
106
# File 'lib/chef-dk/policyfile_lock.rb', line 104

def source
  @source
end

Instance Method Details

#cookbook_pathObject



125
126
127
# File 'lib/chef-dk/policyfile_lock.rb', line 125

def cookbook_path
  File.expand_path(source, relative_paths_root)
end

#identifiersObject



157
158
159
# File 'lib/chef-dk/policyfile_lock.rb', line 157

def identifiers
  @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_path)
end

#scm_profilerObject



129
130
131
132
133
134
135
# File 'lib/chef-dk/policyfile_lock.rb', line 129

def scm_profiler
  if File.exist?(File.join(cookbook_path, ".git"))
    CookbookProfiler::Git.new(cookbook_path)
  else
    CookbookProfiler::NullSCM.new(cookbook_path)
  end
end

#to_lockObject



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/chef-dk/policyfile_lock.rb', line 145

def to_lock

  {
    "version" => identifiers.semver_version,
    "identifier" => identifier,
    "dotted_decimal_identifier" => dotted_decimal_identifier,
    "source" => source,
    "cache_key" => nil,
    "scm_info" => scm_profiler.profile_data
  }
end