Module: RubyTodo::TemplateCommands
- Includes:
- TemplateDisplay
- Included in:
- CLI
- Defined in:
- lib/ruby_todo/commands/template_commands.rb
Instance Method Summary
collapse
#display_template_details, #display_template_list
Instance Method Details
#template_create(name) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/ruby_todo/commands/template_commands.rb', line 46
def template_create(name)
notebook = nil
if options[:notebook]
notebook = RubyTodo::Notebook.find_by(name: options[:notebook])
unless notebook
puts "Notebook '#{options[:notebook]}' not found."
exit 1
end
end
template = RubyTodo::Template.new(
name: name,
notebook: notebook,
title_pattern: options[:title],
description_pattern: options[:description],
tags_pattern: options[:tags],
priority: options[:priority],
due_date_offset: options[:due]
)
if template.save
puts "Template '#{name}' created successfully."
else
puts "Error creating template: #{template.errors.full_messages.join(", ")}"
exit 1
end
end
|
#template_delete(name) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/ruby_todo/commands/template_commands.rb', line 90
def template_delete(name)
template = RubyTodo::Template.find_by(name: name)
unless template
puts "Template '#{name}' not found."
exit 1
end
if template.destroy
puts "Template '#{name}' deleted successfully."
else
puts "Error deleting template: #{template.errors.full_messages.join(", ")}"
exit 1
end
end
|
#template_list ⇒ Object
74
75
76
77
|
# File 'lib/ruby_todo/commands/template_commands.rb', line 74
def template_list
templates = RubyTodo::Template.all
display_template_list(templates)
end
|
#template_show(name) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/ruby_todo/commands/template_commands.rb', line 79
def template_show(name)
template = RubyTodo::Template.find_by(name: name)
unless template
puts "Template '#{name}' not found."
exit 1
end
display_template_details(template)
end
|
#template_use(name, notebook_name) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/ruby_todo/commands/template_commands.rb', line 106
def template_use(name, notebook_name)
template = RubyTodo::Template.find_by(name: name)
unless template
puts "Template '#{name}' not found."
exit 1
end
notebook = RubyTodo::Notebook.find_by(name: notebook_name)
unless notebook
puts "Notebook '#{notebook_name}' not found."
exit 1
end
replacements = {}
if options[:replacements]
options[:replacements].split(",").each do |r|
key, value = r.split(":")
replacements[key] = value if key && value
end
end
task = template.create_task(notebook, replacements)
if task.persisted?
puts "Task created successfully with ID: #{task.id}"
else
puts "Error creating task: #{task.errors.full_messages.join(", ")}"
exit 1
end
end
|