Sha256: 5065bd67ba0722b02d5509964c3af034ac4d6685b084036879ecc3ffce735bf0

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'inifile'
require 'io/console'

# Initializes JiraReport settings.
module JiraReport
  class Settings
    attr_reader :username, :password, :url,\
      :period_from, :period_till

    def initialize(path)
      read(path)
    end

    private

    def read(path)
      loaded = IniFile.load(File.expand_path(path))

      global = loaded[:global] if loaded
      global ||= {}

      @url = global['url']
      @username = global['username']
      @password = global['password']
      @period_from = global['period_from']
      @period_till = global['period_till']

      @url = ask('Jira url in [jira.company.com] format: ') unless @url
      @username = ask('Jira username: ') unless @username
      @password = ask('Jira password: '){
        STDIN.noecho(&:gets).chomp!
      } unless @password
      @period_from = '-1w' unless @period_from
      @period_till = 'now()' unless @period_till

      # TODO: attributes verification
    end

    def ask(message, &block)
      print message
      if block
        yield block
      else
        gets.chomp!
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jira_report-0.0.2 lib/jira_report/settings.rb