Class: GitSwap::Swapper
- Inherits:
-
Object
show all
- Defined in:
- lib/git_swap/swapper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#git_repo? ⇒ Boolean
-
#initialize(args) ⇒ Swapper
constructor
A new instance of Swapper.
-
#method_missing(method, *args) ⇒ Object
Use method_missing for delegation Original ActiveSupport version delegate :usage?, :config?, :edit?, :list?, :version?, :global?, to: :options delegate :profile, :name, :username, :email, :ssh, :ssh_command, :print_list, :configure!, :edit!, :valid_profile?, to: :config.
-
#print_settings ⇒ Object
-
#print_usage ⇒ Object
-
#print_version ⇒ Object
-
#run ⇒ Object
-
#set! ⇒ Object
Constructor Details
#initialize(args) ⇒ Swapper
Returns a new instance of Swapper.
7
8
9
10
11
|
# File 'lib/git_swap/swapper.rb', line 7
def initialize(args)
raise ArgumentError unless args.is_a? Array
@options = GitSwap::Options.new(args)
@config = GitSwap::Config.new(args)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Use method_missing for delegation Original ActiveSupport version delegate :usage?, :config?, :edit?, :list?, :version?, :global?, to: :options delegate :profile, :name, :username, :email, :ssh, :ssh_command, :print_list, :configure!, :edit!, :valid_profile?, to: :config
70
71
72
73
74
75
76
77
78
|
# File 'lib/git_swap/swapper.rb', line 70
def method_missing(method, *args)
if @options.respond_to?(method)
@options.send(method, *args)
elsif @config.respond_to?(method)
@config.send(method, *args)
else
super
end
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5
6
7
|
# File 'lib/git_swap/swapper.rb', line 5
def config
@config
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/git_swap/swapper.rb', line 5
def options
@options
end
|
Instance Method Details
#git_repo? ⇒ Boolean
30
31
32
33
34
35
36
37
|
# File 'lib/git_swap/swapper.rb', line 30
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
|
#print_settings ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/git_swap/swapper.rb', line 55
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 "Swapped to profile #{profile}"
end
end
|
#print_usage ⇒ Object
47
48
49
|
# File 'lib/git_swap/swapper.rb', line 47
def print_usage
puts usage
end
|
#print_version ⇒ Object
51
52
53
|
# File 'lib/git_swap/swapper.rb', line 51
def print_version
puts GitSwap::VERSION
end
|
#run ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/git_swap/swapper.rb', line 13
def run
return unless options.valid_args?
if usage?
print_usage
elsif config?
configure!
elsif edit?
edit!
elsif list?
print_list
elsif version?
print_version
else
set!
end
end
|
#set! ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/git_swap/swapper.rb', line 39
def set!
return unless valid_profile? && git_repo?
set_git_config
set_ssh
print_settings
end
|