Sha256: 344ee6491b3457b961a8ac7a2174e8eddcbb46ba16c0833e6545c21a542b7957

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
require 'ostruct'
module Jiralicious
  module Configuration
    VALID_OPTIONS = [:username, :password, :uri, :api_version, :auth_type]
    DEFAULT_USERNAME = nil
    DEFAULT_PASSWORD = nil
    DEFAULT_AUTH_TYPE = :basic
    DEFAULT_URI = nil
    DEFAULT_API_VERSION = "latest"

    def configure
      yield self
    end

    attr_accessor *VALID_OPTIONS

    # Reset when extended into class
    def self.extended(base)
      base.reset
    end

    def options
      VALID_OPTIONS.inject({}) do |option, key|
        option.merge!(key => send(key))
      end
    end

    def reset
      self.username = DEFAULT_USERNAME
      self.password = DEFAULT_PASSWORD
      self.uri = DEFAULT_URI
      self.api_version = DEFAULT_API_VERSION
      self.auth_type = DEFAULT_AUTH_TYPE
    end

    def load_yml(yml_file)
      if File.exist?(yml_file)
        yml_cfg = OpenStruct.new(YAML.load_file(yml_file))
        yml_cfg.jira.each do |k, v|
          instance_variable_set("@#{k}", v)
        end
      else
        reset
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jiralicious-0.2.0 lib/jiralicious/configuration.rb