Class: Cargo::Config
- Inherits:
-
Object
- Object
- Cargo::Config
- Defined in:
- lib/cargo/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#integrate_with_tracker ⇒ Object
Returns the value of attribute integrate_with_tracker.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #api_available? ⇒ Boolean
- #get_file_data ⇒ Object
-
#initialize(integrate_with_tracker) ⇒ Config
constructor
A new instance of Config.
- #write_project ⇒ Object
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_key ⇒ Object
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_tracker ⇒ Object
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 |
#project ⇒ Object
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
26 27 28 |
# File 'lib/cargo/config.rb', line 26 def api_available? @api_key && @project && @integrate_with_tracker end |
#get_file_data ⇒ Object
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.('~/.cargo.yml') config = YAML.load_file(File.('~/.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_project ⇒ Object
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.('./.cargo.yml'), 'a'){|file| file.write("\nproject: #{@project}\n")} end |