lib/capistrano/committed.rb in capistrano-committed-0.0.5 vs lib/capistrano/committed.rb in capistrano-committed-0.0.6
- old
+ new
@@ -4,38 +4,24 @@
module Capistrano
module Committed
class << self
def get_issue_urls(issue_pattern, postprocess, url_pattern, message)
- fail TypeError, t('committed.error.helpers.valid_param',
- method: __callee__,
- param: 'issue_pattern') unless
- issue_pattern.is_a?(String) ||
- issue_pattern.is_a?(Regexp)
+ check_type __callee__,
+ 'issue_pattern',
+ (issue_pattern.is_a?(String) || issue_pattern.is_a?(Regexp))
- fail TypeError, t('committed.error.helpers.valid_param',
- method: __callee__,
- param: 'postprocess') unless
- postprocess.is_a?(Array)
-
+ check_type __callee__, 'postprocess', postprocess.is_a?(Array)
postprocess.each { |method|
- fail TypeError, t('committed.error.helpers.valid_param',
- method: __callee__,
- param: format('postprocess[:%s]', method.to_s)) unless
- method.is_a?(Symbol)
+ check_type __callee__,
+ format('postprocess[:%s]', method.to_s),
+ method.is_a?(Symbol)
}
- fail TypeError, t('committed.error.helpers.valid_param',
- method: __callee__,
- param: 'url_pattern') unless
- url_pattern.is_a?(String)
+ check_type __callee__, 'url_pattern', url_pattern.is_a?(String)
+ check_type __callee__, 'message', message.is_a?(String)
- fail TypeError, t('committed.error.helpers.valid_param',
- method: __callee__,
- param: 'message') unless
- message.is_a?(String)
-
matches = message.scan(Regexp.new(issue_pattern))
return [] unless matches
matches.map { |match|
issue = match[0]
postprocess.each { |method|
@@ -51,9 +37,16 @@
output << format('%s %s', pad, t('committed.output.issue_links'))
urls.each do |url|
output << format('%s - %s', pad, url)
end
output << format('%s', pad)
+ end
+
+ private
+ def check_type(method, param, condition)
+ fail TypeError, t('committed.error.helpers.valid_param',
+ method: method,
+ param: param) unless condition
end
end
end
end