Class: GitSwitch::Switcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Switcher

Returns a new instance of Switcher.

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/git_switch/switcher.rb', line 10

def initialize(args)
  raise ArgumentError unless args.is_a? Array
  @options = GitSwitch::Options.new(args)
  @config = GitSwitch::Config.new(args)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/git_switch/switcher.rb', line 6

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/git_switch/switcher.rb', line 6

def options
  @options
end

Instance Method Details

#git_repo?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/git_switch/switcher.rb', line 31

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


56
57
58
59
60
61
62
63
64
65
# File 'lib/git_switch/switcher.rb', line 56

def print_settings
  if options.verbose?
    puts "\nGit Config:"
    puts `git config #{git_config_flag} -l --show-origin | grep user`
    puts "\nSSH:"
    puts `ssh-add -l`
  else
    puts "Switched to profile #{profile}"
  end
end


48
49
50
# File 'lib/git_switch/switcher.rb', line 48

def print_usage
  puts usage
end


52
53
54
# File 'lib/git_switch/switcher.rb', line 52

def print_version
  puts GitSwitch::VERSION
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/git_switch/switcher.rb', line 16

def run
  return unless options.valid_args?
  if usage?
    print_usage
  elsif config?
    configure!
  elsif list?
    print_list
  elsif version?
    print_version
  else
    set!
  end
end

#set!Object



40
41
42
43
44
45
46
# File 'lib/git_switch/switcher.rb', line 40

def set!
  return unless valid_profile? && git_repo?

  set_git_config
  set_ssh
  print_settings
end