class Creq::ReqCommand
All commands retrive nothing/info or exception
Constants
- FILE_EXISTS
- TT_NOT_FOUND
- TT_WARNING
Public Class Methods
call(id, title = '', template = nil)
click to toggle source
# File lib/creq/req_cmd.rb, line 10 def self.call(id, title = '', template = nil) title = id if title.empty? body = '' file_name = "#{Settings.src}/#{id}.md" raise CreqCmdError, FILE_EXISTS % file_name if File.exist?(file_name) if template body = read_template_body(template) body = replace_macros(body, {id: id, title: title}) end req = Requirement.new(id: id, title: title, body: body) File.open(file_name, 'w') { |f| Writer.(req, f) } return file_name end
Protected Class Methods
read_template_body(template)
click to toggle source
# File lib/creq/req_cmd.rb, line 29 def self.read_template_body(template) template_file = "#{Settings.tt}/#{template}" template_file += '.md.tt' unless File.exist?(template_file) raise CreqCmdError, TT_NOT_FOUND % template unless File.exist?(template_file) body = File.read(template_file) TT_WARNING % template_file + body end
replace_macros(body, params)
click to toggle source
# File lib/creq/req_cmd.rb, line 38 def self.replace_macros(body, params) new_body = String.new(body) new_body.gsub!('@@id', params[:id]) new_body.gsub!('@@title', params[:title]) new_body end