Class: Emeril::Publisher

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/emeril/publisher.rb

Overview

Takes a path to a cookbook and pushes it up to the Community Site.

Defined Under Namespace

Classes: LoggingUI, SharePlugin

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Publisher

Creates a new instance.

Options Hash (options):

  • an (Logger)

    optional logger instance

  • source_path (String)

    the path to a git repository

  • name (String) — default: required

    the name of the cookbook

  • category (String)

    a Community Site category for the cookbook

  • knife_class (Chef::Knife)

    an alternate Knife plugin class to create, configure, and invoke

Raises:

  • (ArgumentError)

    if any required options are not set



36
37
38
39
40
41
42
43
# File 'lib/emeril/publisher.rb', line 36

def initialize(options = {})
  @logger = options[:logger]
  @source_path = options.fetch(:source_path, Dir.pwd)
  @name = options.fetch(:name) { raise ArgumentError, ":name must be set" }
  @category = options[:category]
  @knife_class = options.fetch(:knife_class, SharePlugin)
  validate_chef_config!
end

Instance Method Details

#runObject

Prepares a sandbox copy of the cookbook and uploads it to the Community Site.



48
49
50
51
52
53
54
55
56
57
# File 'lib/emeril/publisher.rb', line 48

def run
  sandbox_path = sandbox_cookbook
  share = knife_class.new
  share.ui = logging_ui(share.ui)
  share.config[:cookbook_path] = sandbox_path
  share.name_args = [name, category]
  share.run
ensure
  FileUtils.remove_dir(sandbox_path)
end