class Emeril::Publisher
Takes a path to a cookbook and pushes it up to the Community Site.
@author Fletcher Nichol <fnichol@nichol.ca>
Attributes
category[R]
knife_class[R]
logger[R]
name[R]
source_path[R]
Public Class Methods
new(options = {})
click to toggle source
Creates a new instance.
@param [Hash] options configuration for a publisher @option options [Logger] an optional logger instance @option options [String] source_path
the path to a git repository @option options [String] name (required) the name of the cookbook @option options [String] category a Community Site category for the
cookbook
@option options [Chef::Knife] knife_class
an alternate Knife plugin class
to create, configure, and invoke
@raise [ArgumentError] if any required options are not set
# File lib/emeril/publisher.rb, line 35 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
Public Instance Methods
run()
click to toggle source
Prepares a sandbox copy of the cookbook and uploads it to the Community Site.
# File lib/emeril/publisher.rb, line 47 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
Protected Instance Methods
cookbook_files()
click to toggle source
# File lib/emeril/publisher.rb, line 77 def cookbook_files entries = %w[ README.* CHANGELOG.* metadata.{json,rb} attributes definitions files libraries providers recipes resources templates ] Dir.glob("#{source_path}/{#{entries.join(",")}}") end
logging_ui(ui)
click to toggle source
# File lib/emeril/publisher.rb, line 86 def logging_ui(ui) LoggingUI.new(ui.stdout, ui.stderr, ui.stdin, ui.config, logger) end
sandbox_cookbook()
click to toggle source
# File lib/emeril/publisher.rb, line 68 def sandbox_cookbook path = Dir.mktmpdir target = File.join(path, name) debug("Creating cookbook sanbox directory at #{target}") FileUtils.mkdir_p(target) FileUtils.cp_r(cookbook_files, target) path end
validate_chef_config!()
click to toggle source
# File lib/emeril/publisher.rb, line 62 def validate_chef_config! %w[node_name client_key].map(&:to_sym).each do |attr| raise "Chef::Config[:#{attr}] must be set" if ::Chef::Config[attr].nil? end end