pry-note 0.1.0 → 0.2.0

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.
Files changed (3) hide show
  1. data/lib/pry-note/version.rb +1 -1
  2. data/lib/pry-note.rb +56 -16
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module PryNote
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/pry-note.rb CHANGED
@@ -1,3 +1,5 @@
1
+ Pry.config.notes_file = "./notes.yml"
2
+
1
3
  Pry::Commands.create_command "note" do
2
4
  description "Note stuff."
3
5
 
@@ -5,7 +7,8 @@ Pry::Commands.create_command "note" do
5
7
  Usage: note [OPTIONS]
6
8
  Add notes to classes and methods.
7
9
 
8
- e.g note -a Pry#repl #=> add a note to Pry#repl method
10
+ e.g note -a Pry#repl "this is my note" #=> add a note without opening editor
11
+ e.g note -a Pry#repl #=> add a note (with editor) to Pry#repl method
9
12
  e.g note -d Pry#repl:1 #=> delete the 1st note from Pry#repl
10
13
  e.g note -d Pry#repl #=> delete all notes from Pry#repl
11
14
  e.g note -l #=> list all notes
@@ -19,6 +22,7 @@ Pry::Commands.create_command "note" do
19
22
  opt.on :e, :export, "Export notes to a file.", :argument => :optional
20
23
  opt.on :load, "Load notes from a file.", :argument => :optional
21
24
  opt.on :l, :list, "List all notes."
25
+ opt.on "list-all", "List all notes with content."
22
26
  end
23
27
 
24
28
  def setup
@@ -58,8 +62,19 @@ Pry::Commands.create_command "note" do
58
62
  delete_note(opts[:d])
59
63
  elsif opts.present?(:"delete-all")
60
64
  notes.replace({})
61
- elsif opts.present(:load)
65
+ elsif opts.present?(:"list-all")
66
+ list_all
67
+ elsif opts.present?(:load)
62
68
  load_notes(opts[:load])
69
+ else
70
+ meth = Pry::Method.from_binding(target)
71
+ if internal_binding?(target) || !meth
72
+ obj = target.eval("self")
73
+ obj_name = o.is_a?(Module) ? obj.name : obj.class.name
74
+ add_note(obj_name)
75
+ else
76
+ add_note(meth.name_with_owner)
77
+ end
63
78
  end
64
79
  end
65
80
 
@@ -81,10 +96,17 @@ Pry::Commands.create_command "note" do
81
96
 
82
97
  def add_note(name)
83
98
  co_name = code_object_name(retrieve_code_object_safely(name))
84
- note = edit_note(co_name)
99
+
100
+ if args.any?
101
+ note = args.join(" ")
102
+ else
103
+ note = edit_note(co_name)
104
+ end
85
105
 
86
106
  notes[co_name] ||= []
87
107
  notes[co_name] << note
108
+
109
+ output.puts "Added note to #{co_name}!"
88
110
  end
89
111
 
90
112
  def delete_note(name)
@@ -99,7 +121,7 @@ Pry::Commands.create_command "note" do
99
121
  output.puts "Deleted note #{note_number} for #{co_name}!"
100
122
  else
101
123
  notes.delete(co_name)
102
- output.puts "Deleted all notes for #{co_name}!"
124
+ output.puts "Deleted all notes for #{text.bold(co_name)}!"
103
125
  end
104
126
  end
105
127
 
@@ -109,21 +131,20 @@ Pry::Commands.create_command "note" do
109
131
  co_name = code_object_name(code_object)
110
132
 
111
133
  if !notes.has_key?(co_name)
112
- output.puts "No notes saved for #{co_name}"
134
+ output.puts "No notes saved for #{text.bold(co_name)}"
113
135
  return
114
136
  end
115
137
 
116
- output.puts "Showing note(s) for #{co_name}:"
138
+ output.puts text.bold("#{co_name}:\n--")
117
139
 
118
140
  notes[code_object_name(code_object)].each_with_index do |note, index|
119
- output.puts "\nNote #{index + 1}:\n--"
120
- output.puts note
141
+ output.puts "\nNote #{text.bold((index + 1).to_s)}: #{note}"
121
142
  end
122
143
  end
123
144
 
124
145
  def export_notes(file_name=nil)
125
146
  require 'yaml'
126
- file_name ||= "./notes.yml"
147
+ file_name ||= Pry.config.notes_file
127
148
 
128
149
  expanded_path = File.expand_path(file_name)
129
150
  File.open(expanded_path, "w") { |f| f.puts YAML.dump(notes) }
@@ -132,7 +153,7 @@ Pry::Commands.create_command "note" do
132
153
 
133
154
  def load_notes(file_name=nil)
134
155
  require 'yaml'
135
- file_name ||= "./notes.yml"
156
+ file_name ||= Pry.config.notes_file
136
157
 
137
158
  expanded_path = File.expand_path(file_name)
138
159
  if File.exists?(expanded_path)
@@ -140,12 +161,29 @@ Pry::Commands.create_command "note" do
140
161
  end
141
162
  end
142
163
 
164
+ def list_all
165
+ if notes.any?
166
+ output.puts text.bold("Showing all available notes:\n\n")
167
+ notes.each do |key, content|
168
+ begin
169
+ show_note(key)
170
+ output.puts "\n"
171
+ rescue
172
+ end
173
+ end
174
+
175
+ output.puts "\nTo view notes for an item type, e.g: `note -s Klass#method`"
176
+ else
177
+ output.puts "No notes available."
178
+ end
179
+ end
180
+
143
181
  def list_notes
144
182
  if notes.any?
145
- output.puts "Showing all available notes:\n\n"
183
+ output.puts text.bold("Showing all available notes:\n\n")
146
184
  notes.each do |key, content|
147
185
  if retrieve_code_object_from_string(key, target)
148
- output.puts "#{key} has #{content.count} notes"
186
+ output.puts "#{text.bold(key)} has #{content.count} notes"
149
187
  end
150
188
  end
151
189
 
@@ -157,7 +195,6 @@ Pry::Commands.create_command "note" do
157
195
 
158
196
  def add_reminders
159
197
  me = self
160
- max_length = 40
161
198
  reminder = proc do
162
199
  begin
163
200
  code_object = retrieve_code_object_from_string(args.first.to_s, target)
@@ -166,13 +203,16 @@ Pry::Commands.create_command "note" do
166
203
  output.puts "\n\n#{text.bold("Notes:")}\n--\n\n"
167
204
 
168
205
  me.notes[me.code_object_name(code_object)].each_with_index do |note, index|
169
- clipped_note = note.lines.count < 3 ? note : note.lines.to_a[0..2].join + text.bold("<...clipped...>") + " Use `note -s #{co_name}` to view unelided notes."
170
- amended_note = clipped_note.lines.each_with_index.map { |line, idx| idx > 0 ? "#{' ' * ((index + 1).to_s.size + 2)}#{line}" : line }.join
206
+ clipped_note = note.lines.count < 3 ? note : note.lines.to_a[0..2].join +
207
+ text.bold("<...clipped...>") + " Use `note -s #{co_name}` to view unelided notes."
208
+ amended_note = clipped_note.lines.each_with_index.map do |line, idx|
209
+ idx > 0 ? "#{' ' * ((index + 1).to_s.size + 2)}#{line}" : line
210
+ end.join
171
211
  output.puts "#{text.bold((index + 1).to_s)}. #{amended_note}"
172
212
  end
173
213
 
174
214
  end
175
- rescue
215
+ rescue
176
216
  end
177
217
  end
178
218
 
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.1.0
4
+ version: 0.2.0
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: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2012-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake