pry-note 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -123,20 +123,16 @@ Pry::Commands.create_command "note" do
123
123
 
124
124
  # @param [String] co_name Name of note object.
125
125
  # @param [String, nil] note_number_s The note number as a string
126
- # @param [Boolean] must_provide_number Whether note number is
127
- # allowed to be nil.
128
- def ensure_note_number_in_range(co_name, note_number_s, must_provide_number=true)
126
+ def ensure_note_number_in_range(co_name, note_number_s)
129
127
  if notes[co_name]
130
128
  total_notes = notes[co_name].count
131
129
  else
132
130
  raise Pry::CommandError, "No notes available for #{co_name}"
133
131
  end
134
132
 
135
- if !note_number_s && !must_provide_number
133
+ if !note_number_s
136
134
  # we're allowed nil, so just return
137
135
  return
138
- elsif !note_number_s
139
- raise Pry::CommandError, "Must specify a note number. Allowable range is 1-#{total_notes}."
140
136
  elsif note_number_s.to_i < 1 || note_number_s.to_i > total_notes
141
137
  raise Pry::CommandError, "Invalid note number (#{note_number_s}). Allowable range is 1-#{total_notes}."
142
138
  end
@@ -147,23 +143,24 @@ Pry::Commands.create_command "note" do
147
143
  co_name = code_object_name(retrieve_code_object_safely(name))
148
144
 
149
145
  ensure_note_number_in_range(co_name, note_number_s)
146
+ note_number_i = note_number_s ? note_number_s.to_i : notes[co_name].count
150
147
 
151
148
  if message
152
149
  new_content = message
153
150
  else
154
- old_content = notes[co_name][note_number_s.to_i - 1]
151
+ old_content = notes[co_name][note_number_i - 1]
155
152
  new_content = edit_note(co_name, old_content.to_s)
156
153
  end
157
154
 
158
- notes[co_name][note_number_s.to_i - 1] = new_content
159
- output.puts "Updated note #{note_number_s} for #{co_name}!\n"
155
+ notes[co_name][note_number_i - 1] = new_content
156
+ output.puts "Updated note #{note_number_i} for #{co_name}!\n"
160
157
  end
161
158
 
162
159
  def delete_note(name)
163
160
  name, note_number_s = name.split(/:(\d+)$/)
164
161
  co_name = code_object_name(retrieve_code_object_safely(name))
165
162
 
166
- ensure_note_number_in_range(co_name, note_number_s, false)
163
+ ensure_note_number_in_range(co_name, note_number_s)
167
164
 
168
165
  if note_number_s
169
166
  notes[co_name].delete_at(note_number_s.to_i - 1)
@@ -1,3 +1,3 @@
1
1
  module PryNote
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "pry-note"
5
- s.version = "0.2.8"
5
+ s.version = "0.2.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["John Mair (banisterfiend)"]
@@ -160,14 +160,6 @@ describe PryNote do
160
160
 
161
161
  describe "note edit" do
162
162
  describe "errors" do
163
- it 'should error when not given a note number' do
164
- @t.process_command "note add PryNote::TestClass -m 'my note1'"
165
-
166
- capture_exception do
167
- @t.process_command "note edit PryNote::TestClass -m 'bing'"
168
- end.message.should =~ /Must specify a note number/
169
- end
170
-
171
163
  it 'should error when given out of range note number' do
172
164
  @t.process_command "note add PryNote::TestClass -m 'my note1'"
173
165
 
@@ -183,6 +175,16 @@ describe PryNote do
183
175
  end
184
176
  end
185
177
 
178
+ it 'should edit last note when not given a note number' do
179
+ @t.process_command "note add PryNote::TestClass -m 'my note1'"
180
+ @t.process_command "note add PryNote::TestClass -m 'my note2'"
181
+ @t.process_command "note add PryNote::TestClass -m 'my note3'"
182
+
183
+ @t.process_command "note edit PryNote::TestClass -m 'modified note'"
184
+ PryNote.notes["PryNote::TestClass"].count.should == 3
185
+ PryNote.notes["PryNote::TestClass"].last.should =~ /modified note/
186
+ end
187
+
186
188
  it 'should amend the content of a note with -m' do
187
189
  @t.process_command "note add PryNote::TestClass -m 'my note1'"
188
190
  @t.process_command "note edit PryNote::TestClass:1 -m 'bing'"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-note
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: