Class: Tempo::Controllers::Projects
- Inherits:
-
Base
- Object
- Base
- Tempo::Controllers::Projects
show all
- Defined in:
- lib/tempo/controllers/projects_controller.rb
Class Method Summary
collapse
Methods inherited from Base
filter_projects_by_title, fuzzy_match, reassemble_the
Class Method Details
.add(options, args, tags = nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/tempo/controllers/projects_controller.rb', line 45
def add(options, args, tags=nil)
request = reassemble_the args
if @projects.include? request
Views::already_exists_error "project", request
else
project = @projects.new({ title: request, tags: tags })
if @projects.index.length == 1
@projects.current = project
elsif options[:child]
@projects.current << project
end
@projects.save_to_file options
Views::project_added project
end
end
|
.delete(options, args) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/tempo/controllers/projects_controller.rb', line 68
def delete(options, args)
reassemble_the args, options[:delete]
match = match_project :delete, options, args
if match
if match == @projects.current
return Views::ViewRecords::Message.new "cannot delete the active project", category: :error
end
if @projects.index.include?(match)
match.delete
@projects.save_to_file options
Views::projects_list_view if options[:list]
Views::project_deleted match
end
end
end
|
.index(options, args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/tempo/controllers/projects_controller.rb', line 17
def index(options, args)
request = reassemble_the args
if args.empty?
Views::projects_list_view
else
matches = filter_projects_by_title options, args
if matches.empty?
Views::no_match_error "projects", request
else
Views::projects_list_view matches
end
end
end
|
.load(options = {}) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/tempo/controllers/projects_controller.rb', line 8
def load(options={})
directory = options.fetch( :directory, ENV['HOME'])
if File.exist?( File.join( directory, 'tempo', @projects.file ))
@projects.read_from_file options
end
end
|
.tag(options, args) ⇒ Object
add a project with tags, or tag or untag an existing project
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/tempo/controllers/projects_controller.rb', line 88
def tag(options, args)
tags = options[:tag].split if options[:tag]
untags = options[:untag].split if options[:untag]
if options[:add]
add options, args, tags
else
command = options[:tag] ? "tag" : "untag"
match = match_project command, options, args
if match
match.tag tags
match.untag untags
@projects.save_to_file options
Views::project_tags match
end
end
end
|