class Abak::Flow::Configuration
Constants
- AVAILABLE_OPTIONS
TODO: Add old oauth_login and oauth_token
- GITCONFIG_PATTERN
Public Class Methods
new(options = nil)
click to toggle source
# 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
Public Instance Methods
errors()
click to toggle source
# File lib/abak-flow/configuration.rb, line 37 def errors ErrorsPresenter.new(self, @_errors) end
rewrite(options)
click to toggle source
# File lib/abak-flow/configuration.rb, line 24 def rewrite(options) define_options_from_hash(options) write_to_gitconfig! end
valid?()
click to toggle source
# 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
Private Instance Methods
create_public_instance_methods()
click to toggle source
# File lib/abak-flow/configuration.rb, line 43 def create_public_instance_methods AVAILABLE_OPTIONS.each do |name| self.class.send(:define_method, name, -> { @options[name.to_sym] }) end end
dasherize(name)
click to toggle source
# File lib/abak-flow/configuration.rb, line 87 def dasherize(name) name.tr("_", "-") end
define_options_from_gitconfig()
click to toggle source
# File lib/abak-flow/configuration.rb, line 67 def define_options_from_gitconfig read_git_config do |name, value| name = underscore(name) next unless AVAILABLE_OPTIONS.include?(name) @options[name.to_sym] = value end end
define_options_from_hash(hash)
click to toggle source
# File lib/abak-flow/configuration.rb, line 58 def define_options_from_hash(hash) hash.each do|name, value| name = underscore(name.to_s) next unless AVAILABLE_OPTIONS.include?(name) @options[name.to_sym] = value end end
read_git_config(&block)
click to toggle source
# File lib/abak-flow/configuration.rb, line 76 def read_git_config(&block) Manager.git.config.each do |option, value| matches = option.match(GITCONFIG_PATTERN) block.call(underscore(matches[1]), value) if matches && matches[1] end end
underscore(name)
click to toggle source
# File lib/abak-flow/configuration.rb, line 83 def underscore(name) name.tr("-", "_") end
write_to_gitconfig!()
click to toggle source
# File lib/abak-flow/configuration.rb, line 49 def write_to_gitconfig! AVAILABLE_OPTIONS.each do |name| value = @options[name.to_sym] next if value.nil? || value.empty? Manager.git.lib.global_config_set("abak-flow.#{name}", value) end end