class Jirabas::Config

Constants

HomePath
LocalPath
OtherDefaults

Public Class Methods

all() click to toggle source
# File lib/jirabas/config.rb, line 30
def all
  OtherDefaults.merge(home_config).merge(local_config)         end
fetch(key) { || ... } click to toggle source
# File lib/jirabas/config.rb, line 33
def fetch key, &blk
  unless block_given?
    all.fetch key
  else
    all.fetch key do
      value = yield
      write key, value
      value
    end
  end
end
home_config() click to toggle source
# File lib/jirabas/config.rb, line 24
  def home_config
    YAML.load_file(HomePath ).deep_symbolize_keys rescue {}      end

  def local_config
    YAML.load_file(LocalPath).deep_symbolize_keys rescue {}      end

  def all
    OtherDefaults.merge(home_config).merge(local_config)         end

  def fetch key, &blk
    unless block_given?
      all.fetch key
    else
      all.fetch key do
        value = yield
        write key, value
        value
      end
    end
  end

  def write key, value
    FileUtils.touch(HomePath) unless File.exists? HomePath
    write_config_file HomePath, home_config.merge({key => value})
  end

  def write_config_file path, hash
    File.open(HomePath, 'r+') { |f| YAML.dump hash.deep_stringify_keys, f }
  end

  def method_missing key
    fetch key
  end
end
end
init() click to toggle source
# File lib/jirabas/config.rb, line 8
def init
  fetch(:username) {HighLine.new.ask('Please enter your username')}

  fetch(:password) {HighLine.new.ask('Please enter your password') {|h|
                                     h.echo = false  }}

  fetch(:site) { HighLine.new.ask('Please enter your JIRA url like this: https://jira.com') }
end
local_config() click to toggle source
# File lib/jirabas/config.rb, line 27
  def local_config
    YAML.load_file(LocalPath).deep_symbolize_keys rescue {}      end

  def all
    OtherDefaults.merge(home_config).merge(local_config)         end

  def fetch key, &blk
    unless block_given?
      all.fetch key
    else
      all.fetch key do
        value = yield
        write key, value
        value
      end
    end
  end

  def write key, value
    FileUtils.touch(HomePath) unless File.exists? HomePath
    write_config_file HomePath, home_config.merge({key => value})
  end

  def write_config_file path, hash
    File.open(HomePath, 'r+') { |f| YAML.dump hash.deep_stringify_keys, f }
  end

  def method_missing key
    fetch key
  end
end
method_missing(key) click to toggle source
# File lib/jirabas/config.rb, line 54
def method_missing key
  fetch key
end
write(key, value) click to toggle source
# File lib/jirabas/config.rb, line 45
def write key, value
  FileUtils.touch(HomePath) unless File.exists? HomePath
  write_config_file HomePath, home_config.merge({key => value})
end
write_config_file(path, hash) click to toggle source
# File lib/jirabas/config.rb, line 50
def write_config_file path, hash
  File.open(HomePath, 'r+') { |f| YAML.dump hash.deep_stringify_keys, f }
end