Class: GitSu::Switcher

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

Instance Method Summary collapse

Constructor Details

#initialize(config_repository, git, user_list, output) ⇒ Switcher

Returns a new instance of Switcher.



21
22
23
# File 'lib/gitsu/switcher.rb', line 21

def initialize(config_repository, git, user_list, output)
    @config_repository, @git, @user_list, @output = config_repository, git, user_list, output
end

Instance Method Details

#add(user_string) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/gitsu/switcher.rb', line 76

def add(user_string)
    begin
        user = User.parse(user_string)
    rescue User::ParseError => parse_error
        @output.puts parse_error.message
        return
    end
    add_parsed_user user
end

#clear(*scopes) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gitsu/switcher.rb', line 57

def clear(*scopes)
    scope_list = scopes.to_sentence

    if scopes.include? :all
        scopes = [:local, :global, :system]
    end

    @output.puts "Clearing Git #{scopes.pluralize('user')} in #{scope_list} #{scopes.pluralize('scope')}"
    scopes.each do |scope|
        @git.clear_user(scope)
    end
end

#edit_configObject



53
54
55
# File 'lib/gitsu/switcher.rb', line 53

def edit_config
    @git.edit_gitsu_config
end

#listObject



70
71
72
73
74
# File 'lib/gitsu/switcher.rb', line 70

def list
    @user_list.list.each do |user|
        @output.puts @git.render(user)
    end
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gitsu/switcher.rb', line 37

def print_current(*scopes)
    if scopes.include? :all
        @output.puts "Current user: #{@git.render_user(:derived)}"
        @output.puts
        @output.puts "Local: #{@git.render_user(:local)}"
        @output.puts "Global: #{@git.render_user(:global)}"
        @output.puts "System: #{@git.render_user(:system)}"
    else
        scopes.each do |scope|
            unless @git.selected_user(scope).none?
                @output.puts @git.render_user(scope)
            end
        end
    end
end

#request(scope, *user_strings) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitsu/switcher.rb', line 25

def request(scope, *user_strings)
    begin
        parsed, not_parsed = try_to_parse_all user_strings
        found = find_all not_parsed
        combined_user = combine_all(parsed + found)
        select_user combined_user, scope
        parsed.each {|user| add_parsed_user(user) }
    rescue RuntimeError => error
        @output.puts error.message
    end
end