Class: GitSwitch::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#profilesObject (readonly)

Returns the value of attribute profiles.



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

def profiles
  @profiles
end

#selected_profileObject (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

#emailObject



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

#nameObject



16
17
18
# File 'lib/git_switch/config.rb', line 16

def name
  profiles[selected_profile]["name"]
end


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

#profileObject



32
33
34
# File 'lib/git_switch/config.rb', line 32

def profile
  @selected_profile
end

#sshObject



28
29
30
# File 'lib/git_switch/config.rb', line 28

def ssh
  profiles[selected_profile]["ssh"]
end

#usernameObject



20
21
22
# File 'lib/git_switch/config.rb', line 20

def username
  profiles[selected_profile]["username"]
end

#valid_profile?Boolean

Returns:

  • (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