Class: PT::Configuration
Constant Summary collapse
- GLOBAL_CONFIG_PATH =
ENV['HOME'] + "/.pt.yml"
- LOCAL_CONFIG_PATH =
Dir.pwd + '/.pt.yml'
Constants included from IO
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #get_local_config_path ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #save_config(config, path) ⇒ Object
Methods included from IO
#ask, #ask_secret, #choose_action, #choose_filter, #clear, #compact_message, #congrats, #error, #get_open_story_task_from_params, #message, #project_to_s, #prompt, #quit, #select, #select_story_from_paginated_table, #split_lines, #title, #user_s
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pt/configuration.rb', line 11 def initialize Config.load_and_set_settings(GLOBAL_CONFIG_PATH, get_local_config_path) unless (Settings[:pivotal_api_key] ||= ENV['PIVOTAL_API_KEY']) "I can't find info about your Pivotal Tracker account in #{GLOBAL_CONFIG_PATH}." Settings[:pivotal_api_key] = ask "What is your token?" congrats "Thanks!", "Your API id is " + Settings[:pivotal_api_key], "I'm saving it in #{GLOBAL_CONFIG_PATH} so you don't have to log in again." save_config({"pivotal_api_key" => Settings[:pivotal_api_key]}, GLOBAL_CONFIG_PATH) end @client = Client.new Settings[:user_name] ||= @client.me.name || ENV['pivotal_user_name'] Settings[:user_id] ||= @client.me.id || ENV['pivotal_user_id'] Settings[:user_initials] ||= @client.me.initials || ENV['pivotal_user_initials'] unless (Settings[:project_id] ||= ENV['PIVOTAL_PROJECT_ID']) projects = ProjectTable.new(@client.projects) project = select("Please select the project for the current directory", projects) Settings[:project_id], Settings[:project_name] = project.id, project.name end save_config(Settings.to_hash, get_local_config_path()) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/pt/configuration.rb', line 9 def client @client end |
Instance Method Details
#get_local_config_path ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/pt/configuration.rb', line 36 def get_local_config_path # If the local config path does not exist, check to see if we're in a git repo # And if so, try the top level of the checkout if (!File.exist?(LOCAL_CONFIG_PATH) && system('git rev-parse 2> /dev/null')) return `git rev-parse --show-toplevel`.chomp() + '/.pt.yml' else return LOCAL_CONFIG_PATH end end |
#save_config(config, path) ⇒ Object
46 47 48 49 50 |
# File 'lib/pt/configuration.rb', line 46 def save_config(config, path) config = stringify(config) File.new(path, 'w') unless File.exists?(path) File.open(path, 'w') {|f| f.write(config.to_yaml) } end |