Class: PtLogger::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/pt_logger/logger.rb

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



3
4
5
6
# File 'lib/pt_logger/logger.rb', line 3

def initialize
  PivotalTracker::Client.use_ssl = true
  PivotalTracker::Client.token = api_key
end

Instance Method Details

#api_keyObject



13
14
15
# File 'lib/pt_logger/logger.rb', line 13

def api_key
  PtLogger.api_key
end

#append_story_note(message, story_id = nil) ⇒ Object

Command: appends message to PT story story_id. Does nothing if story_id not defined

If story_id is :infer or nil: looks for a story ID in the message (either #999999999 or PT:999999999 )



32
33
34
35
36
37
38
39
# File 'lib/pt_logger/logger.rb', line 32

def append_story_note(message,story_id=nil)
  if (story_id ||= :infer) == :infer
    story_id = extract_story_id_from(message)
  end
  return false unless story_id
  send_story_note!("[#{prepend_text}] #{message}",story_id)
  true
end

#envObject



8
9
10
11
# File 'lib/pt_logger/logger.rb', line 8

def env
  Rails.env
rescue
end

#extract_story_id_from(message) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/pt_logger/logger.rb', line 41

def extract_story_id_from(message)
  if matches = /(PT:|#)(\d+)(\s|$)/i.match(message)
    if matches.size > 3
      matches[2].to_i
    end
  end
end

#prepend_textObject



49
50
51
# File 'lib/pt_logger/logger.rb', line 49

def prepend_text
  ['PtLogger',env].compact.join('::')
end

#projectObject



21
22
23
24
25
# File 'lib/pt_logger/logger.rb', line 21

def project
  @project ||= if project_id
    PivotalTracker::Project.find(project_id)
  end
end

#project_idObject



17
18
19
# File 'lib/pt_logger/logger.rb', line 17

def project_id
  PtLogger.project_id
end

#send_story_note!(message, story_id) ⇒ Object

sends the prepared message as a note on story_id



54
55
56
57
58
59
# File 'lib/pt_logger/logger.rb', line 54

def send_story_note!(message,story_id)
  return unless project
  if story = project.stories.find(story_id)
    story.notes.create(:text => message, :noted_at => Time.now)  # add a new note
  end
end