Class: Posto::Application

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments, todos, options = {}) ⇒ Application

Returns a new instance of Application.



10
11
12
13
14
15
16
# File 'lib/posto/application.rb', line 10

def initialize(arguments, todos, options = {})
  @io = options[:io] || STDOUT
  @list_utility = options[:list_utility] || List
  @file = options[:file] || Posto::File.new(arguments.filename)
  @arguments = arguments
  @todos = todos
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



66
67
68
# File 'lib/posto/application.rb', line 66

def method_missing(symbol, *args)
  STDERR.puts "Unsupported operation '#{symbol} #{args.join "\n"}'"
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/posto/application.rb', line 7

def file
  @file
end

#ioObject

Returns the value of attribute io.



7
8
9
# File 'lib/posto/application.rb', line 7

def io
  @io
end

#todosObject Also known as: list

Returns the value of attribute todos.



7
8
9
# File 'lib/posto/application.rb', line 7

def todos
  @todos
end

Instance Method Details

#add(todo) ⇒ Object



39
40
41
42
# File 'lib/posto/application.rb', line 39

def add(todo)
  @file.write @todos = @list_utility.add(todos, todo)
  todo
end

#commit(n = 1) ⇒ Object



50
51
52
# File 'lib/posto/application.rb', line 50

def commit(n = 1)
  @file.commit("#{done(n)}")
end

#helpObject



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

def help
  @io.puts Posto::Help.help_text
end

#initObject



61
62
63
64
# File 'lib/posto/application.rb', line 61

def init
  @file.touch
  nil
end

#oopsObject



54
55
56
57
58
59
# File 'lib/posto/application.rb', line 54

def oops
  add(`git log -1 --pretty=%B`.strip)
  @file.write @todos = @list_utility.do_bottom(todos)
  @file.oops
  @list_utility.lookup(todos, 1)
end

#runObject



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

def run
  @io.puts send(@arguments.command, *@arguments.params)
end

#start(todo) ⇒ Object Also known as: schedule



44
45
46
47
# File 'lib/posto/application.rb', line 44

def start(todo)
  add(todo)
  @file.commit_alone("scheduled '#{todo}'")
end