Class: ChefCLI::Policyfile::LocalCookbook

Inherits:
CookbookLock show all
Defined in:
lib/chef-cli/policyfile/cookbook_locks.rb

Overview

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

Constant Summary

Constants inherited from CookbookLock

CookbookLock::REQUIRED_LOCK_DATA_KEYS

Instance Attribute Summary collapse

Attributes inherited from CookbookLock

#dotted_decimal_identifier, #identifier, #name, #source_options, #storage_config, #version

Instance Method Summary collapse

Methods inherited from CookbookLock

#chefignore, #cookbook_loader, #cookbook_location_spec, #cookbook_version, #dependencies, #gather_profile_data, #identifiers, #install_locked, #installed?, #symbolize_source_options_keys

Methods included from StorageConfigDelegation

#cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root

Constructor Details

#initialize(name, storage_config) ⇒ LocalCookbook

Returns a new instance of LocalCookbook.



283
284
285
286
287
288
289
290
291
292
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 283

def initialize(name, storage_config)
  @name = name
  @identifier = nil
  @storage_config = storage_config

  @identifier_updated = false
  @version_updated = false
  @cookbook_in_git_repo = nil
  @scm_info = nil
end

Instance Attribute Details

#sourceObject

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



281
282
283
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 281

def source
  @source
end

Instance Method Details

#build_from_lock_data(lock_data) ⇒ Object



327
328
329
330
331
332
333
334
335
336
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 327

def build_from_lock_data(lock_data)
  assert_required_keys_valid!(lock_data)

  @version = lock_data["version"]
  @identifier = lock_data["identifier"]
  @dotted_decimal_identifier = lock_data["dotted_decimal_identifier"]
  @source = lock_data["source"]
  @source_options = symbolize_source_options_keys(lock_data["source_options"])
  @scm_info = lock_data["scm_info"]
end

#cookbook_pathObject



294
295
296
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 294

def cookbook_path
  File.expand_path(source, relative_paths_root)
end

#identifier_updated?Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 373

def identifier_updated?
  @identifier_updated
end

#lock_dataObject



315
316
317
318
319
320
321
322
323
324
325
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 315

def lock_data
  {
    "version" => version,
    "identifier" => identifier,
    "dotted_decimal_identifier" => dotted_decimal_identifier,
    "source" => source,
    "cache_key" => nil,
    "scm_info" => scm_info,
    "source_options" => source_options,
  }
end

#refresh!Object



352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 352

def refresh!
  old_identifier, old_version = @identifier, @version
  @identifier, @dotted_decimal_identifier, @version = nil, nil, nil
  gather_profile_data
  if @identifier != old_identifier
    @identifier_updated = true
  end
  if @version != old_version
    @version_updated = true
  end
  self
end

#scm_infoObject



306
307
308
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 306

def scm_info
  @scm_info
end

#scm_profilerObject



298
299
300
301
302
303
304
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 298

def scm_profiler
  if cookbook_in_git_repo?
    CookbookProfiler::Git.new(cookbook_path)
  else
    CookbookProfiler::NullSCM.new(cookbook_path)
  end
end

#to_lockObject



310
311
312
313
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 310

def to_lock
  refresh_scm_info
  super
end

#updated?Boolean

Returns:

  • (Boolean)


365
366
367
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 365

def updated?
  @identifier_updated || @version_updated
end

#validate!Object



338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 338

def validate!
  if source.nil?
    raise LocalCookbookNotFound, "Cookbook `#{name}' does not have a `source` set, cannot locate cookbook"
  end
  unless File.exist?(cookbook_path)
    raise LocalCookbookNotFound, "Cookbook `#{name}' not found at path source `#{source}` (full path: `#{cookbook_path}')"
  end

  unless cookbook_version.name.to_s == name
    msg = "The cookbook at path source `#{source}' is expected to be named `#{name}', but is now named `#{cookbook_version.name}' (full path: #{cookbook_path})"
    raise MalformedCookbook, msg
  end
end

#version_updated?Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/chef-cli/policyfile/cookbook_locks.rb', line 369

def version_updated?
  @version_updated
end