Class: Obfusc::SetupCommand
- Inherits:
-
Object
- Object
- Obfusc::SetupCommand
- 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
- #generate ⇒ Object
-
#initialize(config) ⇒ SetupCommand
constructor
A new instance of SetupCommand.
- #show ⇒ Object
- #show_usage ⇒ Object
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
#generate ⇒ Object
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 |
#show ⇒ Object
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_usage ⇒ Object
19 20 21 |
# File 'lib/obfusc/commands/setup_command.rb', line 19 def show_usage puts "Usage:\nobfusc setup <#{COMMANDS.join('|')}>" end |