class GitSwitch::Options
Attributes
args[R]
Public Class Methods
new(args)
click to toggle source
# File lib/git_switch/options.rb, line 4 def initialize(args) @args = args end
Public Instance Methods
config?()
click to toggle source
# File lib/git_switch/options.rb, line 42 def config? config_flag? && args.count == 1 end
edit?()
click to toggle source
# File lib/git_switch/options.rb, line 46 def edit? edit_flag? && args.count == 1 end
flags()
click to toggle source
# File lib/git_switch/options.rb, line 8 def flags @flags ||= args.select do |arg| arg.match(/\A\-[ceglv]{1}\z/) || arg.match(/\A\-\-(config|edit|global|list|verbose|version){1}\z/) end end
global?()
click to toggle source
# File lib/git_switch/options.rb, line 58 def global? (flags.include? '-g') || (flags.include? '--global') end
list?()
click to toggle source
# File lib/git_switch/options.rb, line 50 def list? list_flag? && args.count == 1 end
usage?()
click to toggle source
# File lib/git_switch/options.rb, line 38 def usage? args.count == 0 end
valid_args?()
click to toggle source
# File lib/git_switch/options.rb, line 15 def valid_args? if config? return true elsif edit? return true elsif list? return true elsif version? return true elsif verbose? return true elsif no_flags? return true elsif one_flag? && !flag_only? return true elsif usage? return true else puts "Invalid args" return false end end
verbose?()
click to toggle source
# File lib/git_switch/options.rb, line 62 def verbose? verbose_flag? && args.count > 1 end
version?()
click to toggle source
# File lib/git_switch/options.rb, line 54 def version? version_flag? && args.count == 1 end
Private Instance Methods
config_flag?()
click to toggle source
# File lib/git_switch/options.rb, line 68 def config_flag? (flags.include? '-c') || (flags.include? '--config') end
edit_flag?()
click to toggle source
# File lib/git_switch/options.rb, line 72 def edit_flag? (flags.include? '-e') || (flags.include? '--edit') end
flag_count(args)
click to toggle source
# File lib/git_switch/options.rb, line 100 def flag_count(args) args.count {|a| a.start_with? '-'} end
flag_only?()
click to toggle source
# File lib/git_switch/options.rb, line 96 def flag_only? list_flag? || config_flag? || version_flag? end
list_flag?()
click to toggle source
# File lib/git_switch/options.rb, line 76 def list_flag? (flags.include? '-l') || (flags.include? '--list') end
no_flags?()
click to toggle source
# File lib/git_switch/options.rb, line 88 def no_flags? args.length == 1 && flag_count(args) == 0 end
one_flag?()
click to toggle source
# File lib/git_switch/options.rb, line 92 def one_flag? args.length == 2 && flag_count(args) == 1 end
verbose_flag?()
click to toggle source
# File lib/git_switch/options.rb, line 84 def verbose_flag? ((flags.include? '-v') && args.count > 1) || (flags.include? '--verbose') end
version_flag?()
click to toggle source
# File lib/git_switch/options.rb, line 80 def version_flag? ((flags.include? '-v') && args.count == 1) || (flags.include? '--version') end