Class: PtLogger::Logger
- Inherits:
-
Object
- Object
- PtLogger::Logger
- Defined in:
- lib/pt_logger/logger.rb
Instance Method Summary collapse
- #api_key ⇒ Object
-
#append_story_note(message, story_id = nil) ⇒ Object
Command: appends
message
to PT storystory_id
. - #env ⇒ Object
- #extract_story_id_from(message) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #prepend_text ⇒ Object
- #project ⇒ Object
- #project_id ⇒ Object
-
#send_story_note!(message, story_id) ⇒ Object
sends the prepared
message
as a note onstory_id
.
Constructor Details
#initialize ⇒ Logger
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_key ⇒ Object
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(,story_id=nil) if (story_id ||= :infer) == :infer story_id = extract_story_id_from() end return false unless story_id send_story_note!("[#{prepend_text}] #{}",story_id) true end |
#env ⇒ Object
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() if matches = /(PT:|#)(\d+)(\s|$)/i.match() if matches.size > 3 matches[2].to_i end end end |
#prepend_text ⇒ Object
49 50 51 |
# File 'lib/pt_logger/logger.rb', line 49 def prepend_text ['PtLogger',env].compact.join('::') end |
#project ⇒ Object
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_id ⇒ Object
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!(,story_id) return unless project if story = project.stories.find(story_id) story.notes.create(:text => , :noted_at => Time.now) # add a new note end end |