Class: Obfusc::SetupCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/obfusc/commands/setup_command.rb

Overview

Perform tasks related ‘setup` command

Constant Summary collapse

COMMANDS =
%w[generate show].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SetupCommand

Returns a new instance of SetupCommand.



8
9
10
# File 'lib/obfusc/commands/setup_command.rb', line 8

def initialize(config)
  @config = config
end

Class Method Details

.call(config, *args) ⇒ Object



12
13
14
15
16
17
# 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

Instance Method Details

#generateObject



23
24
25
26
27
# 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

#showObject



29
30
31
32
33
34
35
36
37
38
# 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_usageObject



19
20
21
# File 'lib/obfusc/commands/setup_command.rb', line 19

def show_usage
  puts "Usage:\nobfusc setup <#{COMMANDS.join('|')}>"
end