Class: Sonar::RCFile

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sonar/cli/rcfile.rb

Constant Summary collapse

FILENAME =
'sonar.rc'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRCFile


12
13
14
15
# File 'lib/sonar/cli/rcfile.rb', line 12

def initialize
  @path = File.join(File.expand_path('~'), FILENAME)
  @data = load_file
end

Instance Attribute Details

#pathObject

Returns the value of attribute path


9
10
11
# File 'lib/sonar/cli/rcfile.rb', line 9

def path
  @path
end

Instance Method Details

#create_fileObject


17
18
19
20
21
22
23
24
25
26
# File 'lib/sonar/cli/rcfile.rb', line 17

def create_file
  File.open(@path, 'w') do |f|
    f.puts 'email: YOUR_EMAIL'
    f.puts 'access_token: SONAR_TOKEN'
    f.puts 'api_url: https://sonar.labs.rapid7.com'
    f.puts 'format: flat'
    f.puts 'record_limit: 10000'
  end
  puts "Config file setup at: #{@path}"
end

#load_fileObject


28
29
30
31
# File 'lib/sonar/cli/rcfile.rb', line 28

def load_file
  create_file unless File.exist?(@path)
  YAML.load_file(@path)
end