Class: Sah::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sah/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile, verbose: false, format: :table) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sah/config.rb', line 10

def initialize(profile, verbose: false, format: :table)
  @user, @password, @url = nil, nil, nil
  @upstream_fetch_pull_request = false
  @upstream_prevent_push = false
  @upstream_remote_name = "upstream"
  @protocol = "ssh"
  @format = format
  @verbose = verbose

  profile_prefix = "sah\.profile\.#{profile}"
  config_prefix = "sah\.config"

  %x(git config --get-regex "^sah\.").each_line do |line|
    case line
    when /#{profile_prefix}\.user (.*)$/
      @user = $1
    when /#{profile_prefix}\.password (.*)$/
      @password = $1
    when /#{profile_prefix}\.url (.*)$/
      @url = URI.parse $1
    when /#{config_prefix}\.upstream-fetch-pull-request (.*)$/
      @upstream_fetch_pull_request = ($1 == "true")
    when /#{config_prefix}\.upstream-prevent-push (.*)$/
      @upstream_prevent_push = ($1 == "true")
    when /#{config_prefix}\.upstream-remote-name (.*)$/
      @upstream_remote_name = $1
    when /#{config_prefix}\.protocol (.*)$/
      @protocol = $1
    end
  end

  unless @user && @password && @url
    abort "Invalid profile: #{profile}"
  end
  unless ["ssh", "http"].include? @protocol
    abort "protocol must be set to ssh or http: #{@protocol}"
  end
  unless ["json", "table"].include? @format
    abort "format must be set to json or table: #{@format}"
  end
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/sah/config.rb', line 5

def format
  @format
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/sah/config.rb', line 5

def password
  @password
end

#protocolObject

Returns the value of attribute protocol.



5
6
7
# File 'lib/sah/config.rb', line 5

def protocol
  @protocol
end

#upstream_fetch_pull_requestObject

Returns the value of attribute upstream_fetch_pull_request.



5
6
7
# File 'lib/sah/config.rb', line 5

def upstream_fetch_pull_request
  @upstream_fetch_pull_request
end

#upstream_prevent_pushObject

Returns the value of attribute upstream_prevent_push.



5
6
7
# File 'lib/sah/config.rb', line 5

def upstream_prevent_push
  @upstream_prevent_push
end

#upstream_remote_nameObject

Returns the value of attribute upstream_remote_name.



5
6
7
# File 'lib/sah/config.rb', line 5

def upstream_remote_name
  @upstream_remote_name
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/sah/config.rb', line 5

def url
  @url
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/sah/config.rb', line 5

def user
  @user
end

#verboseObject

Returns the value of attribute verbose.



5
6
7
# File 'lib/sah/config.rb', line 5

def verbose
  @verbose
end