class DK::UserCommand

User Defined Command

Constants

REQUIRED_FIELDS

Public Class Methods

new(opts) click to toggle source
# File lib/draftking/cli/commands/user_command.rb, line 5
def initialize(opts)
  opts.each_pair do |k, v|
    singleton_class.class_eval { attr_accessor k.to_s }
    send("#{k}=", v)
  end
  check_required_fields
end

Public Instance Methods

exec!() click to toggle source

Replace current process with execution of @command

# File lib/draftking/cli/commands/user_command.rb, line 14
def exec!
  # Prefix test commands
  command = prefix_command('bin/', Dir.pwd.include?('tumblr_draftking'))
  command = add_config_name(command)
  puts "User Command: #{command}"
  exec(command)
end

Private Instance Methods

add_config_name(command) click to toggle source
# File lib/draftking/cli/commands/user_command.rb, line 30
def add_config_name(command)
  cfig = @config_name ? " --config #{@config_name}" : nil
  return command + cfig unless command.include?(cfig)
  command
end
check_required_fields() click to toggle source
# File lib/draftking/cli/commands/user_command.rb, line 36
def check_required_fields
  REQUIRED_FIELDS.all? do |x|
    # Field is accessible and populated
    next if instance_variables.include?("@#{x}".to_sym) && !send(x.to_s).nil?
    raise ArgumentError, "#{x}: required!"
  end
end
prefix_command(prfx, i_should = true) click to toggle source
# File lib/draftking/cli/commands/user_command.rb, line 24
def prefix_command(prfx, i_should = true)
  # Add prefix to commands, but only once
  return (prfx + @command).gsub(/^(#{prfx})+/, '\1') if i_should
  @command
end