class Shred::Commands::Base
Attributes
command_config[R]
command_name[R]
console[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/shred/commands/base.rb, line 141 def initialize(*args) @command_name = args[2][:invocations][Shred::CLI].last @command_config = Shred::CLI.config['commands'][@command_name] @console = Console.new(thor: self) super configure end
Public Instance Methods
cfg(key, required: true)
click to toggle source
# File lib/shred/commands/base.rb, line 153 def cfg(key, required: true) base_cfg = command_config sub_keys = key.to_s.split('.') value = nil sub_keys.each_with_index do |sub_key, i| if base_cfg && base_cfg.key?(sub_key) value = base_cfg = base_cfg[sub_key] elsif i < sub_keys.length - 1 raise "Missing '#{key}' config for '#{command_name}' command" else value = nil end end raise "Missing '#{key}' config for '#{command_name}' command" if required && !value value end
configure()
click to toggle source
# File lib/shred/commands/base.rb, line 150 def configure end
interpolate_value(value, context: {})
click to toggle source
# File lib/shred/commands/base.rb, line 170 def interpolate_value(value, context: {}) return nil if value.nil? value.gsub(/{[^}]+}/) do |match| ref = match.slice(1, match.length) ref = ref.slice(0, ref.length - 1) if ref =~ /^env\:(.+)$/ env_key = $1.upcase if ENV.key?(env_key) ENV[env_key] else raise "Unset environment variable '#{env_key}' referenced by value '#{value}'" end elsif context.key?(ref.to_sym) context[ref.to_sym] else raise "Unknown interpolation variable '#{ref}' referenced by value '#{value}'" end end end
load_rails()
click to toggle source
# File lib/shred/commands/base.rb, line 194 def load_rails unless @rails_loaded require File.expand_path('config/environment.rb') @rails_loaded = true end end
run_shell_command(command)
click to toggle source
# File lib/shred/commands/base.rb, line 190 def run_shell_command(command) ShellCommandRunner.new(console: console).run(command) end