letters 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -54,3 +54,257 @@ This is significantly easier than breaking apart the pipeline using variable ass
54
54
 
55
55
  The `o` method takes options, too, so you can add a prefix message to the output or choose another output format -- like [YAML]() or [pretty print]().
56
56
 
57
+ ### The methods ###
58
+ <table>
59
+ <tr>
60
+ <th>Letter</th>
61
+ <th>Command</th>
62
+ <th>Options</th>
63
+ <th>Description</th>
64
+ </tr>
65
+
66
+ <tr>
67
+ <td>
68
+ <a href="http://lettersrb.com/api#a">a</a>
69
+ </td>
70
+ <td>
71
+ Assert
72
+ </td>
73
+ <td>
74
+ :message,
75
+ :error_class
76
+ </td>
77
+ <td>
78
+ asserts in the context of its receiver or Letters::AssertionError
79
+ </td>
80
+ </tr>
81
+
82
+ <tr>
83
+ <td>
84
+ <a href="http://lettersrb.com/api#b">b</a>
85
+ </td>
86
+ <td>
87
+ Beep
88
+ </td>
89
+ <td>
90
+ </td>
91
+ <td>
92
+ causes your terminal to beep
93
+ </td>
94
+ </tr>
95
+
96
+ <tr>
97
+ <td>
98
+ <a href="http://lettersrb.com/api#c">c</a>
99
+ </td>
100
+ <td>
101
+ Callstack
102
+ </td>
103
+ <td>
104
+ :message
105
+ </td>
106
+ <td>
107
+ prints the current callstack
108
+ </td>
109
+ </tr>
110
+
111
+ <tr>
112
+ <td>
113
+ <a href="http://lettersrb.com/api#d">d</a>
114
+ </td>
115
+ <td>
116
+ Debugger
117
+ </td>
118
+ <td>
119
+
120
+ </td>
121
+ <td>
122
+ passes control to the debugger
123
+ </td>
124
+ </tr>
125
+
126
+ <tr>
127
+ <td>
128
+ <a href="http://lettersrb.com/api#d1/d2">d1/d2</a>
129
+ </td>
130
+ <td>
131
+ Diff
132
+ </td>
133
+ <td>
134
+ :message,
135
+ :format,
136
+ :stream
137
+ </td>
138
+ <td>
139
+ prints a diff between first and second receivers
140
+ </td>
141
+ </tr>
142
+
143
+ <tr>
144
+ <td>
145
+ <a href="http://lettersrb.com/api#e">e</a>
146
+ </td>
147
+ <td>
148
+ Empty
149
+ </td>
150
+ <td>
151
+ :message
152
+ </td>
153
+ <td>
154
+ raises a Letters::EmptyError if its receiver is empty
155
+ </td>
156
+ </tr>
157
+
158
+ <tr>
159
+ <td>
160
+ <a href="http://lettersrb.com/api#f">f</a>
161
+ </td>
162
+ <td>
163
+ File
164
+ </td>
165
+ <td>
166
+ :format, :name
167
+ </td>
168
+ <td>
169
+ writes its receiver into a file in a given format
170
+ </td>
171
+ </tr>
172
+
173
+ <tr>
174
+ <td>
175
+ <a href="http://lettersrb.com/api#j">j</a>
176
+ </td>
177
+ <td>
178
+ Jump
179
+ </td>
180
+ <td>
181
+ (&block)
182
+ </td>
183
+ <td>
184
+ executes its block in the context of its receiver
185
+ </td>
186
+ </tr>
187
+
188
+ <tr>
189
+ <td>
190
+ <a href="http://lettersrb.com/api#k">k</a>
191
+ </td>
192
+ <td>
193
+ Kill
194
+ </td>
195
+ <td>
196
+ :max
197
+ </td>
198
+ <td>
199
+ raises Letters::KillError after a maximum number of calls
200
+ </td>
201
+ </tr>
202
+
203
+ <tr>
204
+ <td>
205
+ <a href="http://lettersrb.com/api#l">l</a>
206
+ </td>
207
+ <td>
208
+ Logger
209
+ </td>
210
+ <td>
211
+ :format, :level
212
+ </td>
213
+ <td>
214
+ logs its receivers on the available logger instance
215
+ </td>
216
+ </tr>
217
+
218
+ <tr>
219
+ <td>
220
+ <a href="http://lettersrb.com/api#m">m</a>
221
+ </td>
222
+ <td>
223
+ Mark as tainted
224
+ </td>
225
+ <td>
226
+ (true|false)
227
+ </td>
228
+ <td>
229
+ taints (or untaints) its receiver
230
+ </td>
231
+ </tr>
232
+
233
+ <tr>
234
+ <td>
235
+ <a href="http://lettersrb.com/api#n">n</a>
236
+ </td>
237
+ <td>
238
+ Nil
239
+ </td>
240
+ <td>
241
+
242
+ </td>
243
+ <td>
244
+ raises a Letters::NilError if its receiver is nil
245
+ </td>
246
+ </tr>
247
+
248
+ <tr>
249
+ <td>
250
+ <a href="http://lettersrb.com/api#o">o</a>
251
+ </td>
252
+ <td>
253
+ Output
254
+ </td>
255
+ <td>
256
+ :format,
257
+ :stream
258
+ </td>
259
+ <td>
260
+ prints its receiver to standard output
261
+ </td>
262
+ </tr>
263
+
264
+ <tr>
265
+ <td>
266
+ <a href="http://lettersrb.com/api#r">r</a>
267
+ </td>
268
+ <td>
269
+ Ri
270
+ </td>
271
+ <td>
272
+ (method name as symbol)
273
+ </td>
274
+ <td>
275
+ prints RI documentation of its receiver class
276
+ </td>
277
+ </tr>
278
+
279
+ <tr>
280
+ <td>
281
+ <a href="http://lettersrb.com/api#s">s</a>
282
+ </td>
283
+ <td>
284
+ Safety
285
+ </td>
286
+ <td>
287
+ (level number)
288
+ </td>
289
+ <td>
290
+ bumps the safety level (by one or as specified)
291
+ </td>
292
+ </tr>
293
+
294
+ <tr>
295
+ <td>
296
+ <a href="http://lettersrb.com/api#t">t</a>
297
+ </td>
298
+ <td>
299
+ Timestamp
300
+ </td>
301
+ <td>
302
+ :time_format
303
+ </td>
304
+ <td>
305
+ prints out the current timestamp
306
+ </td>
307
+ </tr>
308
+ </table>
309
+
310
+ See full documentation at http://lettersrb.com/api
@@ -2,6 +2,7 @@ require "letters/helpers"
2
2
  require "letters/diff"
3
3
  require "letters/assertion_error"
4
4
  require "letters/empty_error"
5
+ require "letters/kill_error"
5
6
  require "letters/nil_error"
6
7
  require "letters/time_formats"
7
8
 
@@ -93,6 +94,19 @@ module Letters
93
94
  end
94
95
  end
95
96
 
97
+ # Kill
98
+ def k(opts={})
99
+ opts = { max: 0 }.merge(opts)
100
+ opts.merge! :error_class => KillError
101
+ tap do |o|
102
+ @letters_kill_count ||= 0
103
+ if @letters_kill_count >= opts[:max]
104
+ raise opts[:error_class]
105
+ end
106
+ @letters_kill_count += 1
107
+ end
108
+ end
109
+
96
110
  # Log
97
111
  def l(opts={})
98
112
  opts = { level: "info", format: "yaml" }.merge opts
@@ -0,0 +1,4 @@
1
+ module Letters
2
+ class KillError < RuntimeError
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Letters
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -15,7 +15,7 @@ module Letters
15
15
  FileUtils.rm_rf "tmp"
16
16
  end
17
17
 
18
- it "all letter methods but #e and #n return the original object" do
18
+ it "all letter methods but #e, #k and #n return the original object" do
19
19
  # Prevent output and debugging
20
20
  Helpers.should_receive(:call_debugger).any_number_of_times
21
21
  $stdout.should_receive(:puts).any_number_of_times
@@ -23,7 +23,7 @@ module Letters
23
23
  Helpers.should_receive(:change_safety).any_number_of_times
24
24
 
25
25
  ("a".."z").to_a.reject do |letter|
26
- letter =~ /[ejn]/
26
+ letter =~ /[ekjn]/
27
27
  end.select do |letter|
28
28
  hash.respond_to? letter
29
29
  end.each do |letter|
@@ -146,6 +146,27 @@ module Letters
146
146
  end
147
147
  end
148
148
 
149
+ describe "#k (kill)" do
150
+ it 'raises a KillError immediately by default' do
151
+ lambda { hash.k }.should raise_error(KillError)
152
+ end
153
+
154
+ it 'does not raises if number of calls are below max' do
155
+ lambda{ hash.k(max: 1) }.should_not raise_error
156
+ end
157
+
158
+ it 'raises a KillError if number of calls is above max' do
159
+ count = 0
160
+ lambda do
161
+ 10.times do
162
+ hash.k(max: 5)
163
+ count += 1
164
+ end
165
+ end.should raise_error(KillError)
166
+ count.should eq(5)
167
+ end
168
+ end
169
+
149
170
  describe "#l (log)" do
150
171
  it "logs the object if a logger is present and then returns the object" do
151
172
  logger = double 'logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-02 00:00:00.000000000 Z
12
+ date: 2012-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
16
- requirement: &70247244545360 !ruby/object:Gem::Requirement
16
+ requirement: &70220468145960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70247244545360
24
+ version_requirements: *70220468145960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70247244544900 !ruby/object:Gem::Requirement
27
+ requirement: &70220468145520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70247244544900
35
+ version_requirements: *70220468145520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: xml-simple
38
- requirement: &70247244544420 !ruby/object:Gem::Requirement
38
+ requirement: &70220468145100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70247244544420
46
+ version_requirements: *70220468145100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: colorize
49
- requirement: &70247244543900 !ruby/object:Gem::Requirement
49
+ requirement: &70220468144680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70247244543900
57
+ version_requirements: *70220468144680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: debugger
60
- requirement: &70247244543400 !ruby/object:Gem::Requirement
60
+ requirement: &70220468144260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70247244543400
68
+ version_requirements: *70220468144260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
- requirement: &70247244542980 !ruby/object:Gem::Requirement
71
+ requirement: &70220468143840 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70247244542980
79
+ version_requirements: *70220468143840
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70247244542520 !ruby/object:Gem::Requirement
82
+ requirement: &70220468143420 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70247244542520
90
+ version_requirements: *70220468143420
91
91
  description: Letters brings Ruby debugging into the 21st century. It leverages print,
92
92
  the debugger, control transfer, even computer beeps to let you see into your code's
93
93
  state.
@@ -101,6 +101,7 @@ files:
101
101
  - lib/letters/diff.rb
102
102
  - lib/letters/empty_error.rb
103
103
  - lib/letters/helpers.rb
104
+ - lib/letters/kill_error.rb
104
105
  - lib/letters/nil_error.rb
105
106
  - lib/letters/patch/core.rb
106
107
  - lib/letters/patch/object.rb