Class: Ridley::Chef::Cookbook::SyntaxCheck::PersistentSet

Inherits:
Object
  • Object
show all
Defined in:
lib/ridley/chef/cookbook/syntax_check.rb

Overview

Implements set behavior with disk-based persistence. Objects in the set are expected to be strings containing only characters that are valid in filenames.

This class is used to track which files have been syntax checked so that known good files are not rechecked.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_path = nil) ⇒ PersistentSet

Create a new PersistentSet. Values in the set are persisted by creating a file in the cache_path directory. If not given, the value of Chef::Config is used; if that value is not configured, the value of Chef::Config[:path] is used. – history: prior to Chef 11, the cache implementation was based on moneta and configured via cache_options. Knife configs generated with Chef 11 will have `syntax_check_cache_path`, but older configs will have `cache_options`. `cache_options` is marked deprecated in chef/config.rb but doesn't currently trigger a warning. See also: CHEF-3715


45
46
47
48
# File 'lib/ridley/chef/cookbook/syntax_check.rb', line 45

def initialize(cache_path = nil)
  @cache_path = cache_path || Dir.mktmpdir
  @cache_path_created = false
end

Instance Attribute Details

#cache_pathObject (readonly)

Returns the value of attribute cache_path


31
32
33
# File 'lib/ridley/chef/cookbook/syntax_check.rb', line 31

def cache_path
  @cache_path
end

Instance Method Details

#add(value) ⇒ Object

Adds value to the set's collection.


51
52
53
54
# File 'lib/ridley/chef/cookbook/syntax_check.rb', line 51

def add(value)
  ensure_cache_path_created
  FileUtils.touch(File.join(cache_path, value))
end

#include?(value) ⇒ Boolean

Returns true if the set includes value

Returns:

  • (Boolean)

57
58
59
# File 'lib/ridley/chef/cookbook/syntax_check.rb', line 57

def include?(value)
  File.exist?(File.join(cache_path, value))
end