Class: Yolo::Config::Settings

Inherits:
Object
  • Object
show all
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

Author:

  • Alex Fish

Instance Method Summary collapse

Constructor Details

#initializeSettings

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_tokenString

The api token used for deployment

Returns:

  • (String)

    The api token defined in config.yml



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_directoryString

The bundle_directory option is the directory which applications are bundled too

Returns:

  • (String)

    The bundle_directory path defined in config.yml



87
88
89
# File 'lib/yolo/config/settings.rb', line 87

def bundle_directory
  @yaml["paths"]["bundle_directory"]
end

#check_configObject

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_dirObject

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_urlString

The deploy_url is the target url used when deploying

Returns:

  • (String)

    The deployment url defined in config.yml



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_tokenString

The github token used to connect to the github api

Returns:

  • (String)

    The token defined in config.yml



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_configObject

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_yamlObject

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_accountString

The mail account is the account used when sending SMTP mail

Returns:

  • (String)

    The mail account defined in config.yml



125
126
127
128
129
# File 'lib/yolo/config/settings.rb', line 125

def 
  if @yaml["mail"]["account"] != "[email protected]"
    @yaml["mail"]["account"]
  end
end

#mail_fromString

The email address that SMTP mails are sent from

Returns:

  • (String)

    The from address defined in config.yml



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_hostString

The mail host used when sending SMTP mail

Returns:

  • (String)

    The mail host defined in config.yml



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_passwordString

The mail password is the password used when sending SMTP mail

Returns:

  • (String)

    The mail password defined in config.yml



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_portNumber

The mail port used when sending SMTP mail

Returns:

  • (Number)

    The mail port defined in config.yml



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_tokenString

The team token used for deployment

Returns:

  • (String)

    The team token defined in config.yml



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_configObject

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

Parameters:

  • yaml (Hash)

    The settings yaml hash

  • key (String)

    The setting key to update

  • setting (String)

    The setting to update

  • default (String)
    description


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_directoryString

The path to the users home directory, same as ~

Returns:

  • (String)

    The full path to the current users home directory



185
186
187
# File 'lib/yolo/config/settings.rb', line 185

def user_directory
  File.expand_path('~')
end

#yaml_pathString

The path to the users config.yml

Returns:

  • (String)

    The full path to the users config.yml file in their home directory



193
194
195
# File 'lib/yolo/config/settings.rb', line 193

def yaml_path
  "#{user_directory}/.yolo/config.yml"
end

#yolo_dirString

The path to the users .yolo directory, this is directory which contains config.yml

Returns:

  • (String)

    The full path to the users .yolo directory



201
202
203
# File 'lib/yolo/config/settings.rb', line 201

def yolo_dir
  "#{user_directory}/.yolo"
end