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

Returns a new instance of RCFile.



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
27
28
29
30
# 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
  warn = "Please set your email and API token in sonar.rc"
  puts "=" * warn.size
  puts "Config file setup at: #{@path}"
  puts warn
  puts "=" * warn.size
end

#load_fileObject



32
33
34
35
# File 'lib/sonar/cli/rcfile.rb', line 32

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