Class: Gitlab::Triage::CommandBuilders::BaseCommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/triage/command_builders/base_command_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, resource: nil, network: nil) ⇒ BaseCommandBuilder

Returns a new instance of BaseCommandBuilder.



5
6
7
8
9
10
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 5

def initialize(items, resource: nil, network: nil)
  @items = Array.wrap(items)
  @items.delete('')
  @resource = resource&.with_indifferent_access
  @network = network
end

Instance Attribute Details

#itemsObject (readonly, private)

Returns the value of attribute items.



22
23
24
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 22

def items
  @items
end

#networkObject (readonly, private)

Returns the value of attribute network.



22
23
24
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 22

def network
  @network
end

#resourceObject (readonly, private)

Returns the value of attribute resource.



22
23
24
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 22

def resource
  @resource
end

Instance Method Details

#build_commandObject



12
13
14
15
16
17
18
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 12

def build_command
  if items.any?
    [slash_command_string, content_string].compact.join(separator)
  else
    ""
  end
end

#content_stringObject (private)



32
33
34
35
36
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 32

def content_string
  items.map do |item|
    format_item(item)
  end.join(separator)
end

#separatorObject (private)



24
25
26
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 24

def separator
  ' '
end

#slash_command_stringObject (private)



28
29
30
# File 'lib/gitlab/triage/command_builders/base_command_builder.rb', line 28

def slash_command_string
  nil
end