Class: Posto::File

Inherits:
Object
  • Object
show all
Defined in:
lib/posto/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ File

Returns a new instance of File.



5
6
7
# File 'lib/posto/file.rb', line 5

def initialize(filename)
  @filename = filename
end

Instance Method Details

#commit(msg) ⇒ Object



13
14
15
16
# File 'lib/posto/file.rb', line 13

def commit(msg)
  `git add #@filename`
  `git commit -m "#{msg}"`
end

#commit_alone(msg) ⇒ Object



18
19
20
# File 'lib/posto/file.rb', line 18

def commit_alone(msg)
  `git commit -m "#{msg}" #@filename`
end

#oopsObject



22
23
24
# File 'lib/posto/file.rb', line 22

def oops
  `git reset --soft HEAD^`
end

#template(todos) ⇒ Object



38
39
40
# File 'lib/posto/file.rb', line 38

def template(todos)
  "todo\n----\n\n#{todos.join("\n")}\n"
end

#todosObject



30
31
32
33
34
35
36
# File 'lib/posto/file.rb', line 30

def todos
  if ::File.exists? @filename
    List.choose_todo_lines(IO.read(@filename).split("\n"))
  else
    []
  end
end

#touchObject



26
27
28
# File 'lib/posto/file.rb', line 26

def touch
  `touch #@filename`
end

#write(todos) ⇒ Object



9
10
11
# File 'lib/posto/file.rb', line 9

def write(todos)
  IO.write(@filename, template(todos))
end