Class: ChefCLI::Policyfile::ChefRepoCookbookSource

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/policyfile/chef_repo_cookbook_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) {|_self| ... } ⇒ ChefRepoCookbookSource

Constructor

Parameters:

  • path (String)

    path to a chef-repo or the cookbook path under it

Yields:

  • (_self)

Yield Parameters:



37
38
39
40
41
42
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 37

def initialize(path)
  self.path = path
  @ui = UI.new
  @preferred_cookbooks = []
  yield self if block_given?
end

Instance Attribute Details

#pathObject

path to a chef-repo or the cookbook path under it



28
29
30
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 28

def path
  @path
end

#preferred_cookbooksObject (readonly)

Returns the value of attribute preferred_cookbooks.



32
33
34
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 32

def preferred_cookbooks
  @preferred_cookbooks
end

#uiObject

UI object for output



30
31
32
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 30

def ui
  @ui
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 56

def ==(other)
  other.is_a?(self.class) && other.path == path && other.preferred_cookbooks == preferred_cookbooks
end

#default_source_argsObject



44
45
46
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 44

def default_source_args
  [:chef_repo, path]
end

#descObject



80
81
82
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 80

def desc
  "chef_repo(#{path})"
end

#null?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 76

def null?
  false
end

#preferred_for(*cookbook_names) ⇒ Object



48
49
50
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 48

def preferred_for(*cookbook_names)
  preferred_cookbooks.concat(cookbook_names)
end

#preferred_source_for?(cookbook_name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 52

def preferred_source_for?(cookbook_name)
  preferred_cookbooks.include?(cookbook_name)
end

#source_options_for(cookbook_name, cookbook_version) ⇒ Hash

Returns the metadata (path and version) for an individual cookbook

Returns:

  • (Hash)

    metadata for a single cookbook version



72
73
74
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 72

def source_options_for(cookbook_name, cookbook_version)
  { path: cookbook_version_paths[cookbook_name][cookbook_version], version: cookbook_version }
end

#universe_graphHash

Calls the slurp_metadata! helper once to calculate the @universe_graph and @cookbook_version_paths metadata. Returns the @universe_graph.

Returns:

  • (Hash)

    universe_graph



64
65
66
67
# File 'lib/chef-cli/policyfile/chef_repo_cookbook_source.rb', line 64

def universe_graph
  slurp_metadata! if @universe_graph.nil?
  @universe_graph
end