pt_logger 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -63,6 +63,9 @@ NB: there currently isn't a generator to make a config file for you
63
63
  story_id = "1234"
64
64
  PtLogger.log(message_text,story_id)
65
65
 
66
+ The <tt>log</tt> method will return true of logging was successful, else returns false.
67
+ It supresses any StandardErrors that may occur during logging.
68
+
66
69
  ## How to log a message with implicit story ID
67
70
 
68
71
  If the PT story ID is not passed as an explicit parameter to the <tt>log</tt> method,
@@ -71,3 +74,27 @@ The story ID may either be prefixed with "#" or "PT:", for example:
71
74
 
72
75
  PtLogger.log("logging a message to PT:123456 (i.e. this will be added to Pivotal Tracker story number 123456)")
73
76
  PtLogger.log("alternatively #78910 (i.e. this will be added to Pivotal Tracker story number 78910)")
77
+
78
+ ## How to conditionally log a message
79
+
80
+ The <tt>log_if</tt> method can be used to log only if the <tt>condition</tt> is true.
81
+
82
+ The message to log can be constructed in a block, which is handy because this will only be called
83
+ if the condition is true:
84
+
85
+ condition = log_only_if_this == true
86
+ PtLogger.log_if( condition ) do
87
+ "evaluate the message to log here with implicit PT:123456 story id"
88
+ end
89
+
90
+ The message to log can also be provided as a parameter:
91
+
92
+ PtLogger.log_if( condition, "the message to log with implicit PT:123456 story id" )
93
+
94
+ Explicit story IDs can also be provided separately from the message:
95
+
96
+ story_id = 123456
97
+ PtLogger.log_if( condition, "the message to log", story_id )
98
+ PtLogger.log_if( condition, story_id ) do
99
+ "the message to log"
100
+ end
@@ -1,9 +1,52 @@
1
1
  module PtLogger
2
2
 
3
+ # Command: log +message+ to Pivotal Tracker.
4
+ # If +story_id+ is provided, logs to that story, else logs to a story ID
5
+ # referenced in the message itself (as #999 or PT:999).
6
+ #
7
+ # Returns true if log was successful, else false.
8
+ # Supresses any StandardErrors that may occur during logging.
9
+ #
3
10
  def self.log(message,story_id=nil)
4
11
  if pt = PtLogger::Logger.new
5
12
  pt.append_story_note(message,story_id)
13
+ else
14
+ false
6
15
  end
16
+ rescue
17
+ false
18
+ end
19
+
20
+ # Command: log +message+ to Pivotal Tracker if +condition+ is true.
21
+ #
22
+ # The +message+ to log can the result of block evaluation:
23
+ #
24
+ # log_if(condition) do
25
+ # "evaluate the message to log here with implicit PT:999999 story id"
26
+ # end
27
+ #
28
+ # Or the +message+ to log can be passed as an arguent:
29
+ #
30
+ # log_if(condition,message)
31
+ #
32
+ # An explicit story ID can be provided in both block and args form:
33
+ #
34
+ # log_if(condition,story_id) do
35
+ # "evaluate the message to log here"
36
+ # end
37
+ #
38
+ # log_if(condition,message,story_id)
39
+ #
40
+ # If +story_id+ is provided, logs to that story, else logs to a story ID
41
+ # referenced in the message itself (as #999 or PT:999).
42
+ #
43
+ # Returns true if log was successful, else false.
44
+ # Supresses any StandardErrors that may occur during logging.
45
+ #
46
+ def self.log_if(condition,*args)
47
+ return false unless condition
48
+ message = block_given? ? yield : args.shift
49
+ log(message,*args)
7
50
  end
8
51
 
9
52
  end
@@ -33,8 +33,9 @@ class PtLogger::Logger
33
33
  if (story_id ||= :infer) == :infer
34
34
  story_id = extract_story_id_from(message)
35
35
  end
36
- return unless story_id
36
+ return false unless story_id
37
37
  send_story_note!("[#{prepend_text}] #{message}",story_id)
38
+ true
38
39
  end
39
40
 
40
41
  def extract_story_id_from(message)
@@ -1,3 +1,3 @@
1
1
  module PtLogger
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/pt_logger.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Paul Gallagher"]
10
10
  gem.email = ["gallagher.paul@gmail.com"]
11
11
  gem.description = %q{Simple way to log messages to Pivotal tracker stories}
12
- gem.summary = %q{Provides a simple interface for logging infomation on a Pivotal Tracker story. Optionally integrates with Rails logger.}
13
- gem.homepage = ""
12
+ gem.summary = %q{Provides a simple interface for logging infomation on a Pivotal Tracker story}
13
+ gem.homepage = "https://github.com/evendis/pt_logger"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -11,7 +11,7 @@ describe PtLogger do
11
11
  let(:message) { "a test message for the PT:#{test_story_id} story" }
12
12
  subject { resource_class.log(message) }
13
13
  it "logs successfully" do
14
- should be_a(PivotalTracker::Note)
14
+ should be_true
15
15
  end
16
16
  end
17
17
 
@@ -7,21 +7,125 @@ describe PtLogger do
7
7
  describe "##log" do
8
8
  subject { resource_class.log(message) }
9
9
  context "when story_id is defined in the message" do
10
- let(:message) { "test message for story #12345678" }
11
- let(:expected_message) { "[PtLogger] test message for story #12345678" }
12
10
  let(:expected_story_id) { 12345678 }
13
- it "should not call send_story_note!" do
14
- logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
15
- subject
11
+ let(:message) { "test message for story ##{expected_story_id}" }
12
+ let(:expected_message) { "[PtLogger] #{message}" }
13
+ context "when successfully logged" do
14
+ before do
15
+ logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
16
+ end
17
+ it { should be_true }
16
18
  end
17
19
  end
18
20
  context "when story_id is not defined" do
19
21
  let(:message) { "test message without ID" }
22
+ it { should be_false }
20
23
  it "should not call send_story_note!" do
21
24
  logger_class.any_instance.should_receive(:send_story_note!).never
22
25
  subject
23
26
  end
24
27
  end
28
+ context "when some kind of logging error occurs" do
29
+ let(:message) { "test message without ID" }
30
+ before do
31
+ logger_class.any_instance.should_receive(:append_story_note).and_raise(StandardError)
32
+ end
33
+ it { should be_false }
34
+ end
35
+ end
36
+
37
+ describe "#log_if" do
38
+
39
+ context "with implicit story ID" do
40
+ let(:expected_story_id) { 12345678 }
41
+ let(:message) { "test message for story ##{expected_story_id}" }
42
+ let(:expected_message) { "[PtLogger] #{message}" }
43
+
44
+ context "when message passed as block" do
45
+ subject { resource_class.log_if(condition) do
46
+ message
47
+ end }
48
+ context "when successfully logged" do
49
+ let(:condition) { true }
50
+ before do
51
+ logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
52
+ end
53
+ it { should be_true }
54
+ end
55
+ context "when log prevented by condition" do
56
+ let(:condition) { false }
57
+ before do
58
+ logger_class.any_instance.should_receive(:send_story_note!).never
59
+ end
60
+ it { should be_false }
61
+ end
62
+ end
63
+
64
+ context "when message passed as parameter" do
65
+ subject { resource_class.log_if(condition,message) }
66
+ context "when successfully logged" do
67
+ let(:condition) { true }
68
+ before do
69
+ logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
70
+ end
71
+ it { should be_true }
72
+ end
73
+ context "when log prevented by condition" do
74
+ let(:condition) { false }
75
+ before do
76
+ logger_class.any_instance.should_receive(:send_story_note!).never
77
+ end
78
+ it { should be_false }
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ context "with explicit story ID" do
85
+ let(:expected_story_id) { 12345678 }
86
+ let(:message) { "test message" }
87
+ let(:expected_message) { "[PtLogger] #{message}" }
88
+
89
+ context "when message passed as block" do
90
+ subject { resource_class.log_if(condition,expected_story_id) do
91
+ message
92
+ end }
93
+ context "when successfully logged" do
94
+ let(:condition) { true }
95
+ before do
96
+ logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
97
+ end
98
+ it { should be_true }
99
+ end
100
+ context "when log prevented by condition" do
101
+ let(:condition) { false }
102
+ before do
103
+ logger_class.any_instance.should_receive(:send_story_note!).never
104
+ end
105
+ it { should be_false }
106
+ end
107
+ end
108
+
109
+ context "when message passed as parameter" do
110
+ subject { resource_class.log_if(condition,message,expected_story_id) }
111
+ context "when successfully logged" do
112
+ let(:condition) { true }
113
+ before do
114
+ logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
115
+ end
116
+ it { should be_true }
117
+ end
118
+ context "when log prevented by condition" do
119
+ let(:condition) { false }
120
+ before do
121
+ logger_class.any_instance.should_receive(:send_story_note!).never
122
+ end
123
+ it { should be_false }
124
+ end
125
+ end
126
+
127
+ end
128
+
25
129
  end
26
130
 
27
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pt_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -201,7 +201,7 @@ files:
201
201
  - spec/unit/base_spec.rb
202
202
  - spec/unit/config_spec.rb
203
203
  - spec/unit/logger_spec.rb
204
- homepage: ''
204
+ homepage: https://github.com/evendis/pt_logger
205
205
  licenses: []
206
206
  post_install_message:
207
207
  rdoc_options: []
@@ -224,8 +224,7 @@ rubyforge_project:
224
224
  rubygems_version: 1.8.23
225
225
  signing_key:
226
226
  specification_version: 3
227
- summary: Provides a simple interface for logging infomation on a Pivotal Tracker story.
228
- Optionally integrates with Rails logger.
227
+ summary: Provides a simple interface for logging infomation on a Pivotal Tracker story
229
228
  test_files:
230
229
  - spec/fixtures/cassettes/PtLogger/with_embedded_story_id/logs_successfully.yml
231
230
  - spec/integration/base_spec.rb