Class: Gitw::GitAllowedOpt

Inherits:
Object
  • Object
show all
Defined in:
lib/gitw/git_opts.rb

Overview

git allowed options to defined single allowed options to be included in git options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, short: nil, long: nil, with_arg: false, multiple: false) ⇒ GitAllowedOpt

Returns a new instance of GitAllowedOpt.



80
81
82
83
84
85
86
# File 'lib/gitw/git_opts.rb', line 80

def initialize(label, short: nil, long: nil, with_arg: false, multiple: false)
  @label = label.to_s.to_sym
  @short = short
  @long = long
  @with_arg = with_arg
  @multiple = multiple
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



78
79
80
# File 'lib/gitw/git_opts.rb', line 78

def label
  @label
end

#longObject (readonly)

Returns the value of attribute long.



78
79
80
# File 'lib/gitw/git_opts.rb', line 78

def long
  @long
end

#multipleObject (readonly)

Returns the value of attribute multiple.



78
79
80
# File 'lib/gitw/git_opts.rb', line 78

def multiple
  @multiple
end

#shortObject (readonly)

Returns the value of attribute short.



78
79
80
# File 'lib/gitw/git_opts.rb', line 78

def short
  @short
end

#with_argObject (readonly)

Returns the value of attribute with_arg.



78
79
80
# File 'lib/gitw/git_opts.rb', line 78

def with_arg
  @with_arg
end

Instance Method Details

#build_opt(arg = nil) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/gitw/git_opts.rb', line 92

def build_opt(arg = nil)
  return if with_arg && arg.nil?

  opt = []
  opt << (long || short)
  opt << arg if with_arg
  opt.compact
end

#each_label(&block) ⇒ Object



88
89
90
# File 'lib/gitw/git_opts.rb', line 88

def each_label(&block)
  [label, label.to_s, short, long].compact.each(&block)
end