Class: Abak::Flow::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/abak-flow/configuration.rb

Constant Summary collapse

AVAILABLE_OPTIONS =

TODO: Add old oauth_login and oauth_token

%w{login password locale http_proxy}.map(&:freeze)
GITCONFIG_PATTERN =
/abak\-flow\.([\w\d\-\_]+)/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/abak-flow/configuration.rb', line 9

def initialize(options = nil)
  @_errors = Hash.new
  @options = {
    login: nil,
    password: nil,
    locale: "en",
    http_proxy: ENV["http_proxy"] || ENV["HTTP_PROXY"]
  }

  options.nil? ? define_options_from_gitconfig
    : define_options_from_hash(options)

  create_public_instance_methods
end

Instance Method Details

#errorsObject



37
38
39
# File 'lib/abak-flow/configuration.rb', line 37

def errors
  ErrorsPresenter.new(self, @_errors)
end

#rewrite(options) ⇒ Object



24
25
26
27
# File 'lib/abak-flow/configuration.rb', line 24

def rewrite(options)
  define_options_from_hash(options)
  write_to_gitconfig!
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/abak-flow/configuration.rb', line 29

def valid?
  @_errors = Hash.new
  @_errors["login"] = ['blank'] if @options[:login].to_s.empty?
  @_errors["password"] = ['blank'] if @options[:password].to_s.empty?

  @_errors.empty?
end