Module: EPM::Settings

Extended by:
Settings
Included in:
Settings
Defined in:
lib/epm/utils.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



67
68
69
70
# File 'lib/epm/utils.rb', line 67

def check
  install_setup_file unless have_setup_file
  return load_settings
end

#have_setup_fileObject



72
73
74
75
# File 'lib/epm/utils.rb', line 72

def have_setup_file
  settings_file = File.join(ENV['HOME'], '.epm', 'epm-rpc.json')
  File.exists? settings_file
end

#install_log_fileObject



99
100
101
102
103
104
105
# File 'lib/epm/utils.rb', line 99

def install_log_file
  log_file = File.join(ENV['HOME'], '.epm', 'deployed-log.csv')
  unless File.exists? log_file
    File.open(log_file, "w") {}
  end
  return log_file
end

#install_setup_fileObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/epm/utils.rb', line 77

def install_setup_file
  settings_example = File.join(File.dirname(__FILE__), '..', '..', 'settings', 'epm-rpc.json')
  settings_file = File.join(ENV['HOME'], '.epm', 'epm-rpc.json')
  unless Dir.exists? File.dirname settings_file
    FileUtils.mkdir(File.dirname settings_file)
  end
  FileUtils.cp settings_example, settings_file
  settings = File.read settings_file
  print "Before we begin, I need to ask you two personal questions:\n"
  print "What is your primary account which I should be using to send transactions?\n\n"
   = STDIN.gets.chomp
  print "Thanks. #{} is what I will use.\n"
  print "Thanks. Now what is the private key for that account which I should be using?\n\n"
  secret = STDIN.gets.chomp
  print "Thanks. #{secret} is what I will use.\n"
   = "0x#{}" if [0..1] != '0x'
  secret = "0x#{secret}" if secret[0..1] != '0x'
  settings.gsub!("0xact", )
  settings.gsub!("0xsec", secret)
  File.open(settings_file, 'w'){|f| f.write(settings)}
end

#load_settingsObject



107
108
109
110
111
112
113
# File 'lib/epm/utils.rb', line 107

def load_settings
  settings_file = File.join(ENV['HOME'], '.epm', 'epm-rpc.json')
  settings = JSON.parse(File.read(settings_file))
  log_file = install_log_file
  settings["log_file"] = log_file
  return settings
end