Class: ConfigurationProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/configuration_provider.rb

Class Method Summary collapse

Class Method Details

.load_yamlObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/configuration_provider.rb', line 17

def self.load_yaml
  full_config_path = File.expand_path('~/.pairest.yml')

  if File.exist? full_config_path
    config_file = File.read(full_config_path)
    YAML.load(config_file)
  else
    File.write(full_config_path, skeleton_pairest_config)
    puts 'Creating ~/.pairest.yml for you. Edit it before you continue'
    raise SystemExit
  end
end

.skeleton_pairest_configObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/configuration_provider.rb', line 30

def self.skeleton_pairest_config
  "hp:\n" \
  "  name: Haskell Pointer\n" \
  "  email: [email protected]\n" \
  "  key_name: kyle.pointer\n" \
  "eu:\n" \
  "  name: Example User\n" \
  "  email: [email protected]\n" \
  "  key_name: example.user\n"
end

.user_configurationsObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/configuration_provider.rb', line 4

def self.user_configurations
  yaml_users = load_yaml

  yaml_users.map do |initials, details|
    UserConfiguration.new initials: initials,
                          name: details['name'],
                          key: details['key_name'],
                          email: details['email']
  end
end