Class: Marathon::Constraint

Inherits:
Base
  • Object
show all
Defined in:
lib/marathon/constraint.rb

Overview

This class represents a Marathon Constraint. See mesosphere.github.io/marathon/docs/constraints.html for full details.

Instance Attribute Summary

Attributes inherited from Base

#info

Instance Method Summary collapse

Methods inherited from Base

#to_json

Methods included from Error

error_class, error_message, from_response

Constructor Details

#initialize(array) ⇒ Constraint

Create a new constraint object. array: Array returned by API, holds attribute, operator and parameter.



7
8
9
10
11
12
13
# File 'lib/marathon/constraint.rb', line 7

def initialize(array)
  raise Marathon::Error::ArgumentError, 'array must be an Array' unless array.is_a?(Array)
  raise Marathon::Error::ArgumentError,
        'array must be [attribute, operator, parameter] where only parameter is optional' \
    unless array.size != 2 or array.size != 3
  super
end

Instance Method Details

#attributeObject



15
16
17
# File 'lib/marathon/constraint.rb', line 15

def attribute
  info[0]
end

#operatorObject



19
20
21
# File 'lib/marathon/constraint.rb', line 19

def operator
  info[1]
end

#parameterObject



23
24
25
# File 'lib/marathon/constraint.rb', line 23

def parameter
  info[2]
end

#to_pretty_sObject

Returns a string for listing the constraint.



36
37
38
# File 'lib/marathon/constraint.rb', line 36

def to_pretty_s
  info.join(':')
end

#to_sObject



27
28
29
30
31
32
33
# File 'lib/marathon/constraint.rb', line 27

def to_s
  if parameter
    "Marathon::Constraint { :attribute => #{attribute} :operator => #{operator} :parameter => #{parameter} }"
  else
    "Marathon::Constraint { :attribute => #{attribute} :operator => #{operator} }"
  end
end