class Obfusc::SetupCommand

Perform tasks related `setup` command

Constants

COMMANDS

Public Class Methods

call(config, *args) click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 12
def self.call(config, *args)
  model = new(config)
  command = args.first
  command = 'show_usage' unless COMMANDS.include?(command)
  model.public_send(command)
end
new(config) click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 8
def initialize(config)
  @config = config
end

Public Instance Methods

generate() click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 23
def generate
  File.open(config_file, 'w') do |f|
    f.write tokenize(Obfusc::Random.generate!)
  end
end
show() click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 29
def show
  unless File.exist?(config_file)
    puts "#{config_file} does not exist.\nUse: `obfusc setup generate'"
    return
  end
  YAML.load_file(config_file).each do |key, value|
    puts "#{key}:"
    puts "---> #{value.inspect}"
  end
end
show_usage() click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 19
def show_usage
  puts "Usage:\nobfusc setup <#{COMMANDS.join('|')}>"
end

Protected Instance Methods

config_file() click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 57
def config_file
  @config.config_path
end
tokenize(characters_hash) click to toggle source
# File lib/obfusc/commands/setup_command.rb, line 42
def tokenize(characters_hash)
  token = ''
  secret = ''
  characters_hash.sort_by { rand }.each do |key, value|
    token += key
    secret += value
  end
  YAML.dump(
    'prefix' => @config.prefix,
    'suffix' => @config.extension,
    'token' => token,
    'secret' => secret
  )
end