Class: ClientperfConfig

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config_fileObject



10
11
12
# File 'lib/clientperf_config.rb', line 10

def config_file
  File.join(RAILS_ROOT, 'config', 'clientperf.yml')
end

.create_unless_exists(rails_dir) ⇒ Object



14
15
16
17
18
19
# File 'lib/clientperf_config.rb', line 14

def create_unless_exists(rails_dir)
  file = File.join(rails_dir, 'config', 'clientperf.yml')
  return if File.exists?(file)
  
  File.open(file, 'w') { |f| f.puts defaults.to_yaml }
end

.defaultsObject



6
7
8
# File 'lib/clientperf_config.rb', line 6

def defaults
  { 'username' => nil, 'password' => nil }
end

Instance Method Details

#dataObject



22
23
24
25
26
# File 'lib/clientperf_config.rb', line 22

def data
  @data ||= begin
    YAML.load(File.read(self.class.config_file)) rescue self.class.defaults
  end
end

#has_auth?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/clientperf_config.rb', line 29

def has_auth?
  data['username'] && data['password']
end