Class: Yolo::Config::Settings
- Inherits:
-
Object
- Object
- Yolo::Config::Settings
- Includes:
- Singleton
- Defined in:
- lib/yolo/config/settings.rb
Overview
The Settings Singleton class provides yolo with a number of configurable settings using a config.yml file written to the users home directory
Instance Method Summary collapse
-
#api_token ⇒ String
The api token used for deployment.
-
#bundle_directory ⇒ String
The bundle_directory option is the directory which applications are bundled too.
-
#check_config ⇒ Object
Checks for the existance of the config directory in the users home directory and creates it if not present.
-
#create_yolo_dir ⇒ Object
Creates the .yolo directory in the users home directory (~).
-
#deploy_url ⇒ String
The deploy_url is the target url used when deploying.
-
#github_token ⇒ String
The github token used to connect to the github api.
-
#initialize ⇒ Settings
constructor
Creates a new Settings instance with default settings, also checks for the presence of a settings file in the users home directory.
-
#load_config ⇒ Object
Moves the config.yml settings file into the usrs home directory.
-
#load_yaml ⇒ Object
Loads the @yaml instance var.
-
#mail_account ⇒ String
The mail account is the account used when sending SMTP mail.
-
#mail_from ⇒ String
The email address that SMTP mails are sent from.
-
#mail_host ⇒ String
The mail host used when sending SMTP mail.
-
#mail_password ⇒ String
The mail password is the password used when sending SMTP mail.
-
#mail_port ⇒ Number
The mail port used when sending SMTP mail.
-
#team_token ⇒ String
The team token used for deployment.
-
#update_config ⇒ Object
Checks the config file is update to the latest and adds any options that are missing.
-
#update_yaml_setting(yaml, key, setting, default) ⇒ Object
Check the config file for an api_token key and add it if missing.
-
#user_directory ⇒ String
The path to the users home directory, same as ~.
-
#yaml_path ⇒ String
The path to the users config.yml.
-
#yolo_dir ⇒ String
The path to the users .yolo directory, this is directory which contains config.yml.
Constructor Details
#initialize ⇒ Settings
Creates a new Settings instance with default settings, also checks for the presence of a settings file in the users home directory
19 20 21 22 23 24 |
# File 'lib/yolo/config/settings.rb', line 19 def initialize @formatter = Yolo::Formatters::ProgressFormatter.new @error = Yolo::Formatters::ErrorFormatter.new check_config update_config end |
Instance Method Details
#api_token ⇒ String
The api token used for deployment
105 106 107 108 109 |
# File 'lib/yolo/config/settings.rb', line 105 def api_token if @yaml["deployment"]["api_token"] != "example" @yaml["deployment"]["api_token"] end end |
#bundle_directory ⇒ String
The bundle_directory option is the directory which applications are bundled too
87 88 89 |
# File 'lib/yolo/config/settings.rb', line 87 def bundle_directory @yaml["paths"]["bundle_directory"] end |
#check_config ⇒ Object
Checks for the existance of the config directory in the users home directory and creates it if not present
47 48 49 50 51 52 53 |
# File 'lib/yolo/config/settings.rb', line 47 def check_config unless File.directory?(yolo_dir) and File.exist?(yaml_path) @error.run_setup load_config @formatter.setup_complete end end |
#create_yolo_dir ⇒ Object
Creates the .yolo directory in the users home directory (~)
208 209 210 211 212 |
# File 'lib/yolo/config/settings.rb', line 208 def create_yolo_dir unless File.directory?(yolo_dir) FileUtils.mkdir_p(yolo_dir) end end |
#deploy_url ⇒ String
The deploy_url is the target url used when deploying
95 96 97 98 99 |
# File 'lib/yolo/config/settings.rb', line 95 def deploy_url if @yaml["deployment"]["url"] != "http://example.com" @yaml["deployment"]["url"] end end |
#github_token ⇒ String
The github token used to connect to the github api
175 176 177 178 179 |
# File 'lib/yolo/config/settings.rb', line 175 def github_token if @yaml["github"]["token"] != "token" return @yaml["github"]["token"] end end |
#load_config ⇒ Object
Moves the config.yml settings file into the usrs home directory
36 37 38 39 40 41 42 |
# File 'lib/yolo/config/settings.rb', line 36 def load_config create_yolo_dir unless File.exist?(yaml_path) @formatter.config_created(yaml_path) FileUtils.cp_r(File.dirname(__FILE__) + "/config.yml", yaml_path) end end |
#load_yaml ⇒ Object
Loads the @yaml instance var
29 30 31 |
# File 'lib/yolo/config/settings.rb', line 29 def load_yaml @yaml = YAML::load_file yaml_path end |
#mail_account ⇒ String
The mail account is the account used when sending SMTP mail
125 126 127 128 129 |
# File 'lib/yolo/config/settings.rb', line 125 def mail_account if @yaml["mail"]["account"] != "[email protected]" @yaml["mail"]["account"] end end |
#mail_from ⇒ String
The email address that SMTP mails are sent from
165 166 167 168 169 |
# File 'lib/yolo/config/settings.rb', line 165 def mail_from if @yaml["mail"]["from"] != "[email protected]" return @yaml["mail"]["from"] end end |
#mail_host ⇒ String
The mail host used when sending SMTP mail
155 156 157 158 159 |
# File 'lib/yolo/config/settings.rb', line 155 def mail_host if @yaml["mail"]["host"] != "your.server.ip" return @yaml["mail"]["host"] end end |
#mail_password ⇒ String
The mail password is the password used when sending SMTP mail
135 136 137 138 139 |
# File 'lib/yolo/config/settings.rb', line 135 def mail_password if @yaml["mail"]["password"] != "example" @yaml["mail"]["password"] end end |
#mail_port ⇒ Number
The mail port used when sending SMTP mail
145 146 147 148 149 |
# File 'lib/yolo/config/settings.rb', line 145 def mail_port if @yaml["mail"]["port"] != 0 @yaml["mail"]["port"] end end |
#team_token ⇒ String
The team token used for deployment
115 116 117 118 119 |
# File 'lib/yolo/config/settings.rb', line 115 def team_token if @yaml["deployment"]["team_token"] != "example" @yaml["deployment"]["team_token"] end end |
#update_config ⇒ Object
Checks the config file is update to the latest and adds any options that are missing
58 59 60 61 62 63 64 |
# File 'lib/yolo/config/settings.rb', line 58 def update_config if File.directory?(yolo_dir) and File.exist?(yaml_path) @yaml = YAML::load_file yaml_path update_yaml_setting(@yaml, "deployment", "api_token", "example") update_yaml_setting(@yaml, "deployment", "team_token", "example") end end |
#update_yaml_setting(yaml, key, setting, default) ⇒ Object
Check the config file for an api_token key and add it if missing
73 74 75 76 77 78 79 80 81 |
# File 'lib/yolo/config/settings.rb', line 73 def update_yaml_setting(yaml, key, setting, default) unless yaml[key][setting] yaml[key][setting] = default File.open(yaml_path, 'w') {|f| f.write(yaml.to_yaml) } @formatter.config_updated(yaml_path) end end |
#user_directory ⇒ String
The path to the users home directory, same as ~
185 186 187 |
# File 'lib/yolo/config/settings.rb', line 185 def user_directory File.('~') end |
#yaml_path ⇒ String
The path to the users config.yml
193 194 195 |
# File 'lib/yolo/config/settings.rb', line 193 def yaml_path "#{user_directory}/.yolo/config.yml" end |
#yolo_dir ⇒ String
The path to the users .yolo directory, this is directory which contains config.yml
201 202 203 |
# File 'lib/yolo/config/settings.rb', line 201 def yolo_dir "#{user_directory}/.yolo" end |