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.
- data/lib/pry-note/commands.rb +7 -10
- data/lib/pry-note/version.rb +1 -1
- data/pry-note.gemspec +1 -1
- data/test/test_pry_note.rb +10 -8
- metadata +1 -1
data/lib/pry-note/commands.rb
CHANGED
@@ -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
|
-
|
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
|
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][
|
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][
|
159
|
-
output.puts "Updated note #{
|
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
|
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)
|
data/lib/pry-note/version.rb
CHANGED
data/pry-note.gemspec
CHANGED
data/test/test_pry_note.rb
CHANGED
@@ -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'"
|