Class: GitSwitch::Config
- Inherits:
-
Object
- Object
- GitSwitch::Config
- Defined in:
- lib/git_switch/config.rb
Instance Attribute Summary collapse
-
#profiles ⇒ Object
readonly
Returns the value of attribute profiles.
-
#selected_profile ⇒ Object
readonly
Returns the value of attribute selected_profile.
Instance Method Summary collapse
- #email ⇒ Object
- #get_profile(args) ⇒ Object
-
#initialize(args) ⇒ Config
constructor
A new instance of Config.
- #name ⇒ Object
- #print_list ⇒ Object
- #profile ⇒ Object
- #ssh ⇒ Object
- #username ⇒ Object
- #valid_profile? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 |
# File 'lib/git_switch/config.rb', line 6 def initialize(args) @profiles = load! @args = args @selected_profile = get_profile(args) end |
Instance Attribute Details
#profiles ⇒ Object (readonly)
Returns the value of attribute profiles.
5 6 7 |
# File 'lib/git_switch/config.rb', line 5 def profiles @profiles end |
#selected_profile ⇒ Object (readonly)
Returns the value of attribute selected_profile.
5 6 7 |
# File 'lib/git_switch/config.rb', line 5 def selected_profile @selected_profile end |
Instance Method Details
#email ⇒ Object
24 25 26 |
# File 'lib/git_switch/config.rb', line 24 def email profiles[selected_profile]["email"] end |
#get_profile(args) ⇒ Object
12 13 14 |
# File 'lib/git_switch/config.rb', line 12 def get_profile(args) args.detect {|a| !a.start_with? '-'} end |
#name ⇒ Object
16 17 18 |
# File 'lib/git_switch/config.rb', line 16 def name profiles[selected_profile]["name"] end |
#print_list ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/git_switch/config.rb', line 45 def print_list profiles = @profiles.map do |key, value| prefix = value["username"] == current_git_username ? "=>" : " " "#{prefix} #{key}" end puts profiles puts "\n# => - current" if @profiles.any? {|key, value| value["username"] == current_git_username} end |
#profile ⇒ Object
32 33 34 |
# File 'lib/git_switch/config.rb', line 32 def profile @selected_profile end |
#ssh ⇒ Object
28 29 30 |
# File 'lib/git_switch/config.rb', line 28 def ssh profiles[selected_profile]["ssh"] end |
#username ⇒ Object
20 21 22 |
# File 'lib/git_switch/config.rb', line 20 def username profiles[selected_profile]["username"] end |
#valid_profile? ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/git_switch/config.rb', line 36 def valid_profile? if profiles.has_key?(selected_profile) return true else puts "Profile '#{selected_profile}' not found!" return false end end |