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) ⇒ Config

Returns a new instance of Config.



9
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
# File 'lib/sah/config.rb', line 9

def initialize(profile, verbose: false)
  @user, @password, @url = nil, nil, nil
  @upstream_fetch_pull_request = false
  @upstream_prevent_push = false
  @protocol = "ssh"
  @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}\.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
end

Instance Attribute Details

#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

#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