Sha256: 4a5e7840eea31ef5e3cd9941a616f7b19c6730a9d7bf2538469313adf61b4161
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
module Talks module Hooks class << self def create(args) engine = Talks.config.engine options, args = shift_options(args.dup) command_name = command args voice, before_message, after_message = parse options, command_name before_hook = hook(engine, voice, before_message) after_hook = hook(engine, voice, after_message) command = args.join(' ') [before_hook, command, after_hook].join('; ') end private def shift_options(args, options={}) # Check arguments for talks # one-two dashed. -v or --voice if args.first =~ /^-{1,2}[\w-]+$/ options[args[0]] = args[1] args.shift(2) shift_options(args, options) else [options, args] end end def command(args) if args[0..1] == %w(bundle exec) args[2] else args[0] end end def parse(options, command_name) voice = options['-v'] || options['--voice'] || Talks.config.voice_for(command_name.to_sym) || Talks.config.default_voice before_message = options['-bm'] || options['--before-message'] || Talks.config.message_for(command_name, :before) || Talks.config.default_message_for(command_name, :before) after_message = options['-am'] || options['--after-message'] || Talks.config.message_for(command_name, :after) || Talks.config.default_message_for(command_name, :after) [voice, before_message, after_message] end def hook(engine, voice, message) "#{engine} -v #{voice} '#{message}'" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
talks-0.2.0 | lib/talks/hooks.rb |