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.
-
#global ⇒ Object
readonly
Returns the value of attribute global.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
- #check_global(args) ⇒ Object
- #get_profile(args) ⇒ Object
-
#initialize(args) ⇒ Switcher
constructor
Your code goes here…
- #no_flags?(args) ⇒ Boolean
- #one_flag?(args) ⇒ Boolean
- #set! ⇒ Object
- #valid_args?(args) ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Switcher
Your code goes here…
10 11 12 13 14 15 16 |
# File 'lib/git_switch/switcher.rb', line 10 def initialize(args) raise ArgumentError unless args.is_a? Array @config = YAML.load_file(File.('~/.gitswitch')) @global = check_global(args) @profile = get_profile(args) @valid = valid_args?(args) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/git_switch/switcher.rb', line 8 def config @config end |
#global ⇒ Object (readonly)
Returns the value of attribute global.
8 9 10 |
# File 'lib/git_switch/switcher.rb', line 8 def global @global end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
8 9 10 |
# File 'lib/git_switch/switcher.rb', line 8 def profile @profile end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
8 9 10 |
# File 'lib/git_switch/switcher.rb', line 8 def valid @valid end |
Instance Method Details
#check_global(args) ⇒ Object
18 19 20 |
# File 'lib/git_switch/switcher.rb', line 18 def check_global(args) (args.include? '-g') || (args.include? '--global') end |
#get_profile(args) ⇒ Object
22 23 24 25 26 |
# File 'lib/git_switch/switcher.rb', line 22 def get_profile(args) # TODO: RCR - Verify profile exists in config file # TODO: RCR - Handle missing or empty config file args.detect {|a| !a.start_with? '-'} end |
#no_flags?(args) ⇒ Boolean
32 33 34 |
# File 'lib/git_switch/switcher.rb', line 32 def no_flags?(args) args.length == 1 && args.count {|a| a.start_with? '-'} == 0 end |
#one_flag?(args) ⇒ Boolean
36 37 38 |
# File 'lib/git_switch/switcher.rb', line 36 def one_flag?(args) args.length == 2 && args.count {|a| a.start_with?('-')} == 1 end |
#set! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/git_switch/switcher.rb', line 40 def set! return unless valid flag = global ? '--global' : '' puts "\nGit Config:" `git config #{flag} user.name "#{name}"` `git config #{flag} user.username "#{username}"` `git config #{flag} user.email "#{email}"` puts `git config #{flag} -l --show-origin | grep user` puts "\nSSH:" `ssh-add -D` `ssh-add #{ssh}` puts `ssh-add -l` end |
#valid_args?(args) ⇒ Boolean
28 29 30 |
# File 'lib/git_switch/switcher.rb', line 28 def valid_args?(args) no_flags?(args) || one_flag?(args) end |