class Batali::Command
Customized command base for Batali
Constants
- DEFAULT_CONFIGURATION_FILES
Public Class Methods
new(*_)
click to toggle source
Set UI when loading via command
Calls superclass method
# File lib/batali/command.rb, line 20 def initialize(*_) super Batali.ui = ui end
Public Instance Methods
batali_file()
click to toggle source
@return [BFile]
# File lib/batali/command.rb, line 26 def batali_file memoize(:batali_file) do # TODO: Add directory traverse searching path = Utility.clean_path(config.fetch(:file, File.join(Dir.pwd, "Batali"))) ui.verbose "Loading Batali file from: #{path}" bfile = BFile.new(path, cache_directory) if bfile.discover bfile.auto_discover!(config[:environment]) end bfile.data.keys.each do |key| unless bfile.respond_to?(key) ui.warn "Unknown keyword used within Batali file: #{key.inspect}" end end bfile end end
cache_directory(*args)
click to toggle source
@return [String] path to local cache
# File lib/batali/command.rb, line 67 def cache_directory(*args) memoize(["cache_directory", *args].join("_")) do directory = Utility.clean_path(config.fetch(:cache_directory, File.join(user_home, ".batali", "cache"))) ui.debug "Cache directory to persist cookbooks: #{directory}" unless args.empty? directory = Utility.join_path(directory, *args.map(&:to_s)) end FileUtils.mkdir_p(directory) directory end end
dry_run(action) { || ... }
click to toggle source
Do not execute block if dry run
@param action [String] action to be performed @yield block to execute
# File lib/batali/command.rb, line 83 def dry_run(action) if config[:dry_run] ui.warn "Dry run disabled: #{action}" else yield end end
infrastructure?()
click to toggle source
@return [TrueClass, FalseClass] infrastructure mode
# File lib/batali/command.rb, line 92 def infrastructure? config[:infrastructure] || (config[:infrastructure].nil? && manifest.infrastructure) end
manifest()
click to toggle source
@return [Manifest]
# File lib/batali/command.rb, line 45 def manifest memoize(:manifest) do path = Utility.join_path( File.dirname( config.fetch(:file, File.join(Dir.pwd, "batali.manifest")) ), "batali.manifest" ) ui.verbose "Loading manifest file from: #{path}" Manifest.build(path) end end
user_home()
click to toggle source
@return [String] correct user home location for platform
# File lib/batali/command.rb, line 58 def user_home if (RUBY_PLATFORM =~ /mswin|mingw|windows/) Utility.clean_path(ENV.fetch("LOCALAPPDATA", Dir.home)) else Utility.clean_path(Dir.home) end end