Class: Setup
- Inherits:
-
Object
- Object
- Setup
- Defined in:
- lib/Setup.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#config_present ⇒ Object
Returns the value of attribute config_present.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
-
#user_os ⇒ Object
Returns the value of attribute user_os.
-
#user_storage ⇒ Object
Returns the value of attribute user_storage.
Instance Method Summary collapse
- #generate_config ⇒ Object
- #get_name ⇒ Object
- #get_os ⇒ Object
-
#get_storage ⇒ Object
REFACTOR TO PROVIDE PATH.
-
#initialize(user_name, user_os, user_storage, config_present) ⇒ Setup
constructor
A new instance of Setup.
Constructor Details
#initialize(user_name, user_os, user_storage, config_present) ⇒ Setup
Returns a new instance of Setup.
11 12 13 14 15 16 |
# File 'lib/Setup.rb', line 11 def initialize(user_name,user_os,user_storage,config_present) @user_name = user_name @user_os = user_os @user_storage = user_storage @config_present = config_present end |
Instance Attribute Details
#config_present ⇒ Object
Returns the value of attribute config_present.
9 10 11 |
# File 'lib/Setup.rb', line 9 def config_present @config_present end |
#user_name ⇒ Object
Returns the value of attribute user_name.
9 10 11 |
# File 'lib/Setup.rb', line 9 def user_name @user_name end |
#user_os ⇒ Object
Returns the value of attribute user_os.
9 10 11 |
# File 'lib/Setup.rb', line 9 def user_os @user_os end |
#user_storage ⇒ Object
Returns the value of attribute user_storage.
9 10 11 |
# File 'lib/Setup.rb', line 9 def user_storage @user_storage end |
Instance Method Details
#generate_config ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/Setup.rb', line 64 def generate_config() if File.exist?("#{ENV["HOME"]}\\snippet_cli_config.txt") then else FileUtils.cd("#{ENV["HOME"]}") FileUtils.touch("#{ENV["HOME"]}\\snippet_cli_config.txt") File.open("#{ENV["HOME"]}\\snippet_cli_config.txt", "w") { |f| f.write "NAME = #{self.user_name}\n"} File.open("#{ENV["HOME"]}\\snippet_cli_config.txt", "w") { |f| f.write "OS = #{self.user_os}\n"} File.open("#{ENV["HOME"]}\\snippet_cli_config.txt", "w") { |f| f.write "STORAGE = #{self.user_storage}\n"} File.open("#{ENV["HOME"]}\\snippet_cli_config.txt", "w") { |f| f.write "CONFIG_PRESENT = TRUE\n"} end end |
#get_name ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/Setup.rb', line 21 def get_name() puts @leading prompt = TTY::Prompt.new name = prompt.ask("To begin setup, may I have your name?", default: ENV["USER"], active_color: :bright_blue) do |q| q.required true end puts @leading self.user_name = name end |
#get_os ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/Setup.rb', line 31 def get_os() puts @leading prompt = TTY::Prompt.new config_path = prompt.ask("What OS are you using?", default: ENV["OS"], active_color: :bright_blue) do |q| q.required true end if (config_path.include? "Windows") return config_path = "\\Roaming\\AppData\\espanso\\default.yml" elsif (config_path.include?"OS X") return config_path = "#{ENV["HOME"]}/Library/Preferences/espanso/default.yml" else config_path.include?("Linux") return config_path = "#{ENV["HOME"]}/.config/espanso/default.yml" end puts @leading self.user_os=config_path end |
#get_storage ⇒ Object
REFACTOR TO PROVIDE PATH
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/Setup.rb', line 49 def get_storage() puts @leading prompt = TTY::Prompt.new return snippet_storage = prompt.select("Do your store your snippets in Dropbox or a different directory?", default: 1, active_color: :bright_blue) do || .enum "." .choice "No I use the default folder.", 1 .choice "I use Dropbox.", 2 .choice "I use Google Drive", 3 .choice "I use Another Directory.", 4 end puts @leading self.user_storage = snippet_storage end |