Module: CookbookOmnifetch

Defined in:
lib/cookbook-omnifetch.rb,
lib/cookbook-omnifetch/git.rb,
lib/cookbook-omnifetch/base.rb,
lib/cookbook-omnifetch/path.rb,
lib/cookbook-omnifetch/github.rb,
lib/cookbook-omnifetch/version.rb,
lib/cookbook-omnifetch/exceptions.rb,
lib/cookbook-omnifetch/integration.rb,
lib/cookbook-omnifetch/artifactserver.rb

Defined Under Namespace

Classes: AbstractFunction, ArtifactserverLocation, BaseLocation, CookbookValidationFailure, GitCommandError, GitError, GitLocation, GitNotInstalled, GithubLocation, Integration, MismatchedCookbookName, MissingConfiguration, NotACookbook, NullValue, OmnifetchError, PathLocation

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.cache_pathString

Returns the filepath to the location where data will be cached.

Returns:

  • (String)


70
71
72
# File 'lib/cookbook-omnifetch.rb', line 70

def self.cache_path
  integration.cache_path
end

.cached_cookbook_class#from_path

Returns an Object (generally a class, but not required) that respsonds to #from_path and returns an object representing the cookbook. In berkshelf, this would be a Berkshelf::CachedCookbook (inherits from Ridley::Chef::Cookbook). The object returned by ‘cached_cookbook_class.from_path(path)` is expected to respond to #version and #cookbook_name

Returns:

  • (#from_path)


94
95
96
# File 'lib/cookbook-omnifetch.rb', line 94

def self.cached_cookbook_class
  integration.cached_cookbook_class
end

.configure {|String| ... } ⇒ Object

Yields the Integration object which configures Dependency Injection classes for the library.

Yields:

  • (String)

See Also:



64
65
66
# File 'lib/cookbook-omnifetch.rb', line 64

def self.configure
  yield integration
end

.cookbook?(path) ⇒ Boolean

Returns true or false if the given path contains a Chef Cookbook

Parameters:

  • path (#to_s)

    path of directory to reflect on

Returns:

  • (Boolean)


115
116
117
# File 'lib/cookbook-omnifetch.rb', line 115

def self.cookbook?(path)
  File.exists?(File.join(path, "metadata.json")) || File.exists?(File.join(path, "metadata.rb"))
end

.init(dependency, options = {}) ⇒ ~BaseLocation?

Create a new instance of a Location class given dependency and options. The type of class is determined by the values in the given options Hash.

If you do not provide an option with a matching location id, nil is returned.

Examples:

Create a git location

Location.init(dependency, git: 'git://github.com/berkshelf/berkshelf.git')

Create a GitHub location

Location.init(dependency, github: 'berkshelf/berkshelf')

Parameters:

  • dependency (Dependency)
  • options (Hash) (defaults to: {})

Returns:



30
31
32
33
34
35
36
# File 'lib/cookbook-omnifetch.rb', line 30

def self.init(dependency, options = {})
  if klass = klass_from_options(options)
    klass.new(dependency, options)
  else
    nil
  end
end

.integrationString

Returns the Integration object which configures Dependency Injection classes for the library.

Returns:

  • (String)


56
57
58
# File 'lib/cookbook-omnifetch.rb', line 56

def self.integration
  @integration ||= Integration.new
end

.shell_out_class#shell_out

Returns an Object (generally a class or module, but that’s not required) that responds to the #shell_out method to run an external command. The shell_out method accepts a single string for the command to run, and returns an object that responds to #success?, #stdout and #stderr.

Note that this shell_out method should not raise errors automatically.

Returns:

  • (#shell_out)


82
83
84
# File 'lib/cookbook-omnifetch.rb', line 82

def self.shell_out_class
  integration.shell_out_class
end

.storage_pathPathname

Returns a pathname object representing the location where cookbooks are cached.

NOTE: In the original berks code, this is generally accessed via Berkshelf.cookbook_store.storage_path

Returns:

  • (Pathname)


105
106
107
# File 'lib/cookbook-omnifetch.rb', line 105

def self.storage_path
  integration.storage_path
end

.which(executable) ⇒ String?

Location an executable in the current user’s $PATH

Returns:

  • (String, nil)

    the path to the executable, or nil if not present



42
43
44
45
46
47
48
49
50
51
# File 'lib/cookbook-omnifetch.rb', line 42

def self.which(executable)
  if File.file?(executable) && File.executable?(executable)
    executable
  elsif ENV['PATH']
    path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
      File.executable?(File.join(p, executable))
    end
    path && File.expand_path(executable, path)
  end
end