Class: Gitw::GitOpts
- Inherits:
-
Object
- Object
- Gitw::GitOpts
- Defined in:
- lib/gitw/git_opts.rb
Overview
git options allow to define available options and to create standard args for execution
Instance Method Summary collapse
- #add(label, arg = nil) ⇒ Object
- #allow(label, **kwargs) ⇒ Object
- #from(options) ⇒ Object
- #from_a(options) ⇒ Object
- #from_h(options) ⇒ Object
-
#initialize ⇒ GitOpts
constructor
A new instance of GitOpts.
- #opts ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ GitOpts
Returns a new instance of GitOpts.
8 9 10 11 12 13 |
# File 'lib/gitw/git_opts.rb', line 8 def initialize @allowed = [] @allowed_index = {} @opts = [] end |
Instance Method Details
#add(label, arg = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/gitw/git_opts.rb', line 40 def add(label, arg = nil) @opts << [label, arg] self end |
#allow(label, **kwargs) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gitw/git_opts.rb', line 15 def allow(label, **kwargs) allowed_opt = GitAllowedOpt.new(label, **kwargs) return unless allowed_opt @allowed << allowed_opt allowed_opt.each_label do |allowed_opt_label| @allowed_index[allowed_opt_label] = allowed_opt end self end |
#from(options) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/gitw/git_opts.rb', line 64 def from() case when Hash then from_h() when Array then from_a() else self end end |
#from_a(options) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/gitw/git_opts.rb', line 46 def from_a() .each do |option| add(option) end self end |
#from_h(options) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/gitw/git_opts.rb', line 54 def from_h() .each do |k, v| next if v == false add(k, v) end self end |
#opts ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/gitw/git_opts.rb', line 27 def opts @opts.map do |label, arg| linked_allowed_opt = @allowed_index[label] next unless linked_allowed_opt linked_allowed_opt.build_opt(arg) end.compact end |
#to_a ⇒ Object
36 37 38 |
# File 'lib/gitw/git_opts.rb', line 36 def to_a opts.flatten end |