Module: Jiralicious::Configuration

Included in:
Jiralicious
Defined in:
lib/jiralicious/configuration.rb

Overview

Base configuration module for Jiralicious

Constant Summary collapse

VALID_OPTIONS =

Array of available attributes

[:username, :password, :uri, :api_version, :auth_type, :project, :oauth_secret, :oauth_secret_filename, :oauth_pass_phrase, :oauth_consumer_key, :config_path]
DEFAULT_USERNAME =

Default user name set prior to login attempt

nil
DEFAULT_PASSWORD =

Default password set prior to login attempt

nil
DEFAULT_AUTH_TYPE =

Authentication is either :basic or :cookie (depricated)

:basic
DEFAULT_URI =

Default URI set prior to login attempt

nil
DEFAULT_API_VERSION =

Default API Version can be set any valid version or “latest”

"latest"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Reset when extended into class

Arguments

:base (required)



37
38
39
# File 'lib/jiralicious/configuration.rb', line 37

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Enables block configuration mode

Yields:

  • (_self)

Yield Parameters:



24
25
26
# File 'lib/jiralicious/configuration.rb', line 24

def configure
  yield self
end

#load_yml(yml_file, mode = nil) ⇒ Object

Loads the provided YML file.

Can provide either direct or relational path to the file. It is recommended to send a direct path due to dynamic loading and/or different file locations due to different deployment methods.

Direct Path

/usr/project/somepath_to_file/jira.yml

Relational Path

Rails.root.to_s + “/config/jira.yml”

“./config/jira.yml”

Arguments

:yml_file (required) path to file to load

:mode (optional) used to define environment type



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/jiralicious/configuration.rb', line 85

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

#optionsObject

Pass options to set the values



44
45
46
47
48
# File 'lib/jiralicious/configuration.rb', line 44

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

#resetObject

Resets all attributes to default values



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jiralicious/configuration.rb', line 53

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
	  self.project = nil
	  self.oauth_secret = nil
	  self.oauth_secret_filename = nil
	  self.oauth_pass_phrase = nil
	  self.oauth_consumer_key = nil
	  self.config_path = nil
end