Class: Envandle::Argset

Inherits:
Object
  • Object
show all
Defined in:
lib/envandle/argset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, *args, &block) ⇒ Argset

Returns a new instance of Argset.



3
4
5
6
7
8
9
10
11
12
# File 'lib/envandle/argset.rb', line 3

def initialize(context, *args, &block)
  @context = context
  @args = args
  h = Envandle.options!(args)
  @options = {}
  h.each do |k, v|
    @options[k.to_s.to_sym] = v
  end
  @block = block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



14
15
16
# File 'lib/envandle/argset.rb', line 14

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



14
15
16
# File 'lib/envandle/argset.rb', line 14

def block
  @block
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/envandle/argset.rb', line 14

def options
  @options
end

Instance Method Details

#args_and_optionsObject



30
31
32
33
34
35
36
37
38
# File 'lib/envandle/argset.rb', line 30

def args_and_options
  @args_and_options ||= begin
    if @options.empty?
      [*@args]
    else
      [*@args, @options]
    end
  end
end

#clear_referenceObject



20
21
22
23
24
25
26
27
28
# File 'lib/envandle/argset.rb', line 20

def clear_reference
  @args = [@args[0]]
  @options.delete :path
  @options.delete :git
  @options.delete :github
  @options.delete :ref
  @options.delete :branch
  @options.delete :tag
end

#contextual_groupsObject



50
51
52
# File 'lib/envandle/argset.rb', line 50

def contextual_groups
  @contextual_groups ||= get_contexutual_groups
end

#dupObject



16
17
18
# File 'lib/envandle/argset.rb', line 16

def dup
  Argset.new(@context, *@args.dup, @options.dup, &@block)
end

#get_contexutual_groupsObject



54
55
56
57
58
59
# File 'lib/envandle/argset.rb', line 54

def get_contexutual_groups
  if option = @options[:groups] || @options[:group]
    return option.is_a?(Array) ? option : [option]
  end
  @context.groups_or_default
end

#send_to(o) ⇒ Object



46
47
48
# File 'lib/envandle/argset.rb', line 46

def send_to(o)
  o.__send__ @context, *args_and_options, &@block
end

#to_sObject



40
41
42
43
44
# File 'lib/envandle/argset.rb', line 40

def to_s
  a = [@context, *args_and_options]
  a << @block if @block
  a.to_s
end