Class: Cargo::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integrate_with_tracker) ⇒ Config

Returns a new instance of Config.



7
8
9
10
# File 'lib/cargo/config.rb', line 7

def initialize(integrate_with_tracker)
  @integrate_with_tracker = integrate_with_tracker
  get_file_data
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/cargo/config.rb', line 5

def api_key
  @api_key
end

#integrate_with_trackerObject

Returns the value of attribute integrate_with_tracker.



5
6
7
# File 'lib/cargo/config.rb', line 5

def integrate_with_tracker
  @integrate_with_tracker
end

#projectObject

Returns the value of attribute project.



5
6
7
# File 'lib/cargo/config.rb', line 5

def project
  @project
end

Instance Method Details

#api_available?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cargo/config.rb', line 26

def api_available?
  @api_key && @project && @integrate_with_tracker
end

#get_file_dataObject



12
13
14
15
16
17
18
19
# File 'lib/cargo/config.rb', line 12

def get_file_data
  raise "No api key in ~/.cargo.yml" unless File.exists? File.expand_path('~/.cargo.yml')
  config = YAML.load_file(File.expand_path('~/.cargo.yml'))
  @api_key = config["api_key"] if config
  raise "No api key in ~/.cargo.yml" if @api_key.nil?
  config = YAML.load_file('.cargo.yml') if File.exists? '.cargo.yml'
  @project = config["project"] if config
end

#write_projectObject



21
22
23
24
# File 'lib/cargo/config.rb', line 21

def write_project
  raise "No project id is set" unless @project
  File.open(File.expand_path('./.cargo.yml'), 'a'){|file| file.write("\nproject: #{@project}\n")}
end