class AgileNotifier::Configuration

Public Class Methods

set(&blk) click to toggle source
# File lib/agile_notifier/configuration.rb, line 14
def set(&blk)
  new(&blk)
end

Private Class Methods

new(&blk) click to toggle source
# File lib/agile_notifier/configuration.rb, line 5
def initialize(&blk)
  @current_module = Object.const_get(self.class.to_s.split('::').first)
  @its_args = Hash.new
  options = Commander.order(ARGV)
  @build_number = options[:build_number]
  instance_eval(&blk)
end

Public Instance Methods

alert_on_fail() click to toggle source
# File lib/agile_notifier/configuration.rb, line 87
def alert_on_fail
  alert(:blame, :fail)
end
alert_on_fix() click to toggle source
# File lib/agile_notifier/configuration.rb, line 95
def alert_on_fix
  alert(:praise, :fix)
end
alert_on_unstable() click to toggle source
# File lib/agile_notifier/configuration.rb, line 91
def alert_on_unstable
  alert(:warn, :unstable)
end
alert_on_wip() click to toggle source
# File lib/agile_notifier/configuration.rb, line 109
def alert_on_wip
  Judger.on_limit(@its, organize_args)
end
ci_get(ci_type) click to toggle source
# File lib/agile_notifier/configuration.rb, line 27
def ci_get(ci_type)
  @ci = @current_module.const_get(ci_type).new(@ci_url, @ci_job, @build_number)
end
ci_job(job) click to toggle source
# File lib/agile_notifier/configuration.rb, line 23
def ci_job(job)
  @ci_job = job
end
ci_url(url) click to toggle source
# File lib/agile_notifier/configuration.rb, line 19
def ci_url(url)
  @ci_url = url
end
its_auth(username, password) click to toggle source
# File lib/agile_notifier/configuration.rb, line 67
def its_auth(username, password)
  @its_args.merge!(:username => username, :password => password)
end
its_get(its_type) click to toggle source
# File lib/agile_notifier/configuration.rb, line 71
def its_get(its_type)
  @its = @current_module.const_get(its_type).new(@its_args)
end
its_set_wip(project, query, limit) click to toggle source
# File lib/agile_notifier/configuration.rb, line 75
def its_set_wip(project, query, limit)
  @its.set_limit(project, query, limit)
end
its_url(url) click to toggle source
# File lib/agile_notifier/configuration.rb, line 63
def its_url(url)
  @its_args[:url] = url
end
play(voice) click to toggle source
# File lib/agile_notifier/configuration.rb, line 83
def play(voice)
  @voice = voice
end
scm_auth(auth) click to toggle source
# File lib/agile_notifier/configuration.rb, line 40
def scm_auth(auth)
  username = auth.fetch(:username, nil)
  password = auth.fetch(:password, nil)
  token = auth.fetch(:token, nil)
  @scm_authentication = username && password ? {:basic_auth => {:username => username, :password => password}} : nil
  @scm_authentication = {:Authorization => "token #{token}"} if token
end
scm_get(scm_type, args = {}) click to toggle source
# File lib/agile_notifier/configuration.rb, line 48
def scm_get(scm_type, args = {})
  enterprise = args.fetch(:enterprise, false)      
  params = [@scm_url]
  params.push(@scm_authentication) if @scm_authentication
  if enterprise
    @scm = @current_module.const_get(scm_type).new_enterprise_version(*params)
  else
    @scm = @current_module.const_get(scm_type).new(*params)
  end
  @scm_repos.each do |repo|
    @scm.add_repository(repo)
  end
  return @scm
end
scm_repo(repo) click to toggle source
# File lib/agile_notifier/configuration.rb, line 35
def scm_repo(repo)
  @scm_repos ||= []
  @scm_repos.push(repo)
end
scm_url(url) click to toggle source
# File lib/agile_notifier/configuration.rb, line 31
def scm_url(url)
  @scm_url = url
end
speak(language) click to toggle source
# File lib/agile_notifier/configuration.rb, line 79
def speak(language)
  @language = language.to_s.downcase.intern
end

Private Instance Methods

alert(composer_type, judger_type) click to toggle source
# File lib/agile_notifier/configuration.rb, line 99
def alert(composer_type, judger_type)
  composer_type = composer_type.to_s.downcase
  judger_type = judger_type.to_s.downcase
  composer_method = "#{composer_type}_committer_of_a_commit".intern
  judger_method = "on_#{judger_type}".intern
  build = @ci.job.current_build
  text = Composer.send(composer_method, repo: @scm.repository, revision: build.revision, language: @language)
  Judger.send(judger_method, build, text, organize_args)
end
organize_args() click to toggle source
# File lib/agile_notifier/configuration.rb, line 113
def organize_args
  args = Hash.new
  args[:language] = @language
  args[:voice] = @voice if @voice
  args
end