Module: PryNote

Defined in:
lib/pry-note.rb,
lib/pry-note/version.rb

Constant Summary collapse

VERSION =
"0.2.7"

Class Method Summary collapse

Class Method Details

.code_object_name(co) ⇒ String

Returns the ‘name` of the code object.

Returns:

  • (String)

    the ‘name` of the code object



46
47
48
49
50
51
52
53
54
# File 'lib/pry-note.rb', line 46

def self.code_object_name(co)
  if co.is_a?(Pry::Method)
    co.name_with_owner
  elsif co.is_a?(Pry::WrappedModule)
    co.name
  elsif co <= Pry::Command
    co.command_name
  end
end

.export_notes(file_name = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/pry-note.rb', line 21

def self.export_notes(file_name=nil)
  return if !file_name && !Pry.config.notes_file
  file_name ||= Pry.config.notes_file
  expanded_path = File.expand_path(file_name)

  if PryNote.notes && PryNote.notes.any?
    File.open(expanded_path, "w") { |f| f.puts YAML.dump(PryNote.notes) }
  end
end

.load_notes(file_name = nil) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/pry-note.rb', line 12

def self.load_notes(file_name=nil)
  return if !file_name && !Pry.config.notes_file
  file_name ||= Pry.config.notes_file
  expanded_path = File.expand_path(file_name)
  if File.exists?(expanded_path)
    PryNote.notes = YAML.load File.read(expanded_path)
  end
end

.notesObject



9
# File 'lib/pry-note.rb', line 9

def self.notes() @notes ||= {}; end

.notes=(o) ⇒ Object



10
# File 'lib/pry-note.rb', line 10

def self.notes=(o) @notes = o; end

.retrieve_code_object_safely(name, target, _pry_) ⇒ Pry::Method, ...

Returns The code_object.

Returns:

  • (Pry::Method, Pry::WrappedModule, Pry::Command)

    The code_object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pry-note.rb', line 32

def self.retrieve_code_object_safely(name, target, _pry_)
  code_object = Pry::Helpers::CommandHelpers.retrieve_code_object_from_string(name, target)  ||
    _pry_.commands.find_command(name)

  if !code_object
    raise Pry::CommandError, "No code object found named #{name}"
  elsif code_object.name.to_s == ""
    raise Pry::CommandError, "Object #{name} doesn't have a proper name, can't create note"
  end

  code_object
end