Class: GitSwitch::Switcher
- Inherits:
-
Object
- Object
- GitSwitch::Switcher
- Defined in:
- lib/git_switch/switcher.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #email ⇒ Object
- #git_repo? ⇒ Boolean
- #global? ⇒ Boolean
-
#initialize(args) ⇒ Switcher
constructor
A new instance of Switcher.
- #list? ⇒ Boolean
- #name ⇒ Object
- #print_list ⇒ Object
- #print_settings(flag = '') ⇒ Object
- #print_usage ⇒ Object
- #profile ⇒ Object
- #run ⇒ Object
- #set! ⇒ Object
- #ssh ⇒ Object
- #usage? ⇒ Boolean
- #username ⇒ Object
- #valid_profile? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Switcher
Returns a new instance of Switcher.
7 8 9 10 11 |
# File 'lib/git_switch/switcher.rb', line 7 def initialize(args) raise ArgumentError unless args.is_a? Array = GitSwitch::Options.new(args) @config = GitSwitch::Config.new(args) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/git_switch/switcher.rb', line 5 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/git_switch/switcher.rb', line 5 def end |
Instance Method Details
#email ⇒ Object
35 36 37 |
# File 'lib/git_switch/switcher.rb', line 35 def email config.email end |
#git_repo? ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/git_switch/switcher.rb', line 55 def git_repo? if GitHelper.git_repo? || global? return true else puts "Not a git repo. Please run from a git repo or run with `-g` to update global settings." return false end end |
#global? ⇒ Boolean
51 52 53 |
# File 'lib/git_switch/switcher.rb', line 51 def global? .global? end |
#list? ⇒ Boolean
47 48 49 |
# File 'lib/git_switch/switcher.rb', line 47 def list? .list? end |
#name ⇒ Object
27 28 29 |
# File 'lib/git_switch/switcher.rb', line 27 def name config.name end |
#print_list ⇒ Object
83 84 85 |
# File 'lib/git_switch/switcher.rb', line 83 def print_list config.print_list end |
#print_settings(flag = '') ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/git_switch/switcher.rb', line 87 def print_settings(flag = '') if .verbose? puts "\nGit Config:" puts `git config #{flag} -l --show-origin | grep user` puts "\nSSH:" puts `ssh-add -l` else puts "Switched to profile #{profile}" end end |
#print_usage ⇒ Object
79 80 81 |
# File 'lib/git_switch/switcher.rb', line 79 def print_usage puts usage end |
#profile ⇒ Object
23 24 25 |
# File 'lib/git_switch/switcher.rb', line 23 def profile config.profile end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/git_switch/switcher.rb', line 13 def run if usage? print_usage elsif list? print_list else set! end end |
#set! ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/git_switch/switcher.rb', line 68 def set! return unless .valid_args? && valid_profile? return unless git_repo? flag = global? ? '--global' : '' set_git_config(flag) set_ssh print_settings(flag) end |
#ssh ⇒ Object
39 40 41 |
# File 'lib/git_switch/switcher.rb', line 39 def ssh config.ssh end |
#usage? ⇒ Boolean
43 44 45 |
# File 'lib/git_switch/switcher.rb', line 43 def usage? .usage? end |
#username ⇒ Object
31 32 33 |
# File 'lib/git_switch/switcher.rb', line 31 def username config.username end |
#valid_profile? ⇒ Boolean
64 65 66 |
# File 'lib/git_switch/switcher.rb', line 64 def valid_profile? config.valid_profile? end |