class Souschef::Berkshelf
Includes slave functions that do all the work
Attributes
cookbook_dir[RW]
opts[RW]
Public Class Methods
new(opts)
click to toggle source
# File lib/souschef/berkshelf.rb, line 6 def initialize(opts) @opts = opts end
Public Instance Methods
berks_create()
click to toggle source
Public - Tell Berkshelf
to create a cookbook
Returns nil
# File lib/souschef/berkshelf.rb, line 13 def berks_create remove_old_readme Souschef::Print.info 'Creating cookbook structure' if @opts[:verbose] i, o, e, w = Open3.popen3(berks_cmd) print_open3_stdout(o) if @opts[:verbose] remove_vagrantfile print_open3_stdout(e) i.close fail 'Berks failed' unless w.value == 0 end
Private Instance Methods
berks_cmd()
click to toggle source
Private - Returns berkshelf command depending on the path
Returns String
# File lib/souschef/berkshelf.rb, line 30 def berks_cmd if @opts[:path] == Dir.pwd "#{which_berks} cookbook #{@opts[:cookbook]} ." else path = @opts[:path].gsub("#{Dir.pwd}/", '') "#{which_berks} cookbook #{@opts[:cookbook]} #{path}" end end
colour(msg)
click to toggle source
Private - Print
out a colorized message
msg - String message
Returns nil
# File lib/souschef/berkshelf.rb, line 80 def colour(msg) puts msg.colorize(:red) end
info_msg(msg)
click to toggle source
Private - Print
out info message
msg - String message
Returns nil
# File lib/souschef/berkshelf.rb, line 89 def info_msg(msg) puts msg.colorize(:yellow) end
print_open3_stdout(stdout)
click to toggle source
Private - Print
out Open3 STDOUT stream
stdout - Open3 stdout stream
Return nil
# File lib/souschef/berkshelf.rb, line 71 def print_open3_stdout(stdout) stdout.read.split("\n").each { |msg| puts msg.colorize(:green) } end
remove_old_readme()
click to toggle source
Private - Remove README from cookbook dir
Returns nil
# File lib/souschef/berkshelf.rb, line 42 def remove_old_readme readme = File.join(@opts[:path], 'README.md') File.delete(readme) if File.exist?(readme) end
remove_vagrantfile()
click to toggle source
Private - Remove README from cookbook dir
Returns nil
# File lib/souschef/berkshelf.rb, line 50 def remove_vagrantfile vagrantfile = File.join(@opts[:path], 'Vagrantfile') File.delete(vagrantfile) if File.exist?(vagrantfile) end
which_berks()
click to toggle source
Private - Obtain berks executable full path
Returns String
# File lib/souschef/berkshelf.rb, line 58 def which_berks i, o, e, w = Open3.popen3('which berks') fail 'berks executable not found on system' if w.value.to_i > 0 i.close e.close o.read.chomp end