Class: Sah::Config
- Inherits:
-
Object
- Object
- Sah::Config
- Defined in:
- lib/sah/config.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#upstream_fetch_pull_request ⇒ Object
Returns the value of attribute upstream_fetch_pull_request.
-
#upstream_prevent_push ⇒ Object
Returns the value of attribute upstream_prevent_push.
-
#upstream_remote_name ⇒ Object
Returns the value of attribute upstream_remote_name.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(profile, verbose: false) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(profile, verbose: false) ⇒ 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 |
# File 'lib/sah/config.rb', line 10 def initialize(profile, verbose: false) @user, @password, @url = nil, nil, nil @upstream_fetch_pull_request = false @upstream_prevent_push = false @upstream_remote_name = "upstream" @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}\.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 end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/sah/config.rb', line 5 def password @password end |
#protocol ⇒ Object
Returns the value of attribute protocol.
5 6 7 |
# File 'lib/sah/config.rb', line 5 def protocol @protocol end |
#upstream_fetch_pull_request ⇒ Object
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_push ⇒ Object
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_name ⇒ Object
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 |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/sah/config.rb', line 5 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/sah/config.rb', line 5 def user @user end |
#verbose ⇒ Object
Returns the value of attribute verbose.
5 6 7 |
# File 'lib/sah/config.rb', line 5 def verbose @verbose end |