Class: Rhea::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/rhea/command.rb

Constant Summary collapse

KEY_PREFIX =
'rhea-'
IMAGE_EXPRESSION_SEPARATOR =
'____'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression:, image: nil, process_count: nil, created_at: nil) ⇒ Command

Returns a new instance of Command.



8
9
10
11
12
13
# File 'lib/rhea/command.rb', line 8

def initialize(expression:, image: nil, process_count: nil, created_at: nil)
  self.expression = expression
  self.image = image || Rhea.configuration.default_image
  self.process_count = process_count
  self.created_at = created_at
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/rhea/command.rb', line 3

def created_at
  @created_at
end

#expressionObject

Returns the value of attribute expression.



3
4
5
# File 'lib/rhea/command.rb', line 3

def expression
  @expression
end

#imageObject

Returns the value of attribute image.



3
4
5
# File 'lib/rhea/command.rb', line 3

def image
  @image
end

#process_countObject

Returns the value of attribute process_count.



3
4
5
# File 'lib/rhea/command.rb', line 3

def process_count
  @process_count
end

Instance Method Details

#attributesObject



15
16
17
18
19
20
21
22
# File 'lib/rhea/command.rb', line 15

def attributes
  {
    expression: expression,
    image: image,
    process_count: process_count,
    created_at: created_at
  }
end

#keyObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/rhea/command.rb', line 24

def key
  command_hash = Digest::MD5.hexdigest("#{image}#{expression}")[0..3]
  command_for_host = expression.downcase.gsub(/[^-a-z0-9]+/i, '-').squeeze('-')
  key = "#{KEY_PREFIX}#{command_hash}-#{command_for_host}"
  max_host_name_length = 62
  key = key[0,max_host_name_length]
  # The key can't end with a '-'
  key.gsub!(/\-+$/, '')
  key
end