Class: Purse::Pocket
- Inherits:
-
Object
- Object
- Purse::Pocket
- Defined in:
- lib/purse/pocket.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #commit ⇒ Object
- #delete ⇒ Object
- #edit(name) {|note| ... } ⇒ Object
- #exists? ⇒ Boolean
- #find(name) ⇒ Object
- #init ⇒ Object
-
#initialize(path) ⇒ Pocket
constructor
A new instance of Pocket.
- #load_notes ⇒ Object
- #notes ⇒ Object
- #notes_paths ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #re_encrypt(password) ⇒ Object
- #remote ⇒ Object
- #set_remote(remote_url) ⇒ Object
Constructor Details
#initialize(path) ⇒ Pocket
Returns a new instance of Pocket.
5 6 7 8 |
# File 'lib/purse/pocket.rb', line 5 def initialize(path) Purse.check_for_parameter('path', path) @path = File.(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/purse/pocket.rb', line 3 def path @path end |
Instance Method Details
#commit ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/purse/pocket.rb', line 57 def commit git.add('.') # return if git.status.changed.empty? git.commit_all("Changes via Purse #{Time.now}") rescue Git::GitExecuteError => e puts e end |
#delete ⇒ Object
19 20 21 |
# File 'lib/purse/pocket.rb', line 19 def delete FileUtils.rm_rf(@path) end |
#edit(name) {|note| ... } ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/purse/pocket.rb', line 29 def edit(name) Purse.check_for_parameter('name', name) begin note = find(name) rescue Purse::MissingFile note = Note.new(path, name, nil) end yield(note) @notes = load_notes end |
#exists? ⇒ Boolean
15 16 17 |
# File 'lib/purse/pocket.rb', line 15 def exists? File.readable?(@path) && File.directory?(@path) end |
#find(name) ⇒ Object
23 24 25 26 27 |
# File 'lib/purse/pocket.rb', line 23 def find(name) Purse.check_for_parameter('name', name) note = notes.find {|note| note.name == name } note ? note : raise(Purse::MissingFile, "Could note find the note named #{note}") end |
#init ⇒ Object
10 11 12 13 |
# File 'lib/purse/pocket.rb', line 10 def init FileUtils.mkdir_p(@path) unless exists? git end |
#load_notes ⇒ Object
48 49 50 |
# File 'lib/purse/pocket.rb', line 48 def load_notes notes_paths.collect {|note_path| Note.load(File.dirname(note_path), File.basename(note_path, '.note'))} end |
#notes ⇒ Object
40 41 42 |
# File 'lib/purse/pocket.rb', line 40 def notes @notes ||= load_notes end |
#notes_paths ⇒ Object
44 45 46 |
# File 'lib/purse/pocket.rb', line 44 def notes_paths Dir[File.join(@path, '*.note')] end |
#pull ⇒ Object
77 78 79 |
# File 'lib/purse/pocket.rb', line 77 def pull git.pull('origin') end |
#push ⇒ Object
73 74 75 |
# File 'lib/purse/pocket.rb', line 73 def push git.push('origin') end |
#re_encrypt(password) ⇒ Object
52 53 54 55 |
# File 'lib/purse/pocket.rb', line 52 def re_encrypt(password) Purse.check_for_parameter('password', password) notes.collect {|n| n.save(password) } end |
#remote ⇒ Object
65 66 67 |
# File 'lib/purse/pocket.rb', line 65 def remote git.remotes.first end |
#set_remote(remote_url) ⇒ Object
69 70 71 |
# File 'lib/purse/pocket.rb', line 69 def set_remote(remote_url) git.add_remote('origin', remote_url) end |