Class: Diaspora::Cluster::Creator::Guarantor

Inherits:
Object
  • Object
show all
Defined in:
lib/diaspora-cluster-creator/guarantor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name = :technology, minimum_value = 2) ⇒ Guarantor

Returns a new instance of Guarantor.



6
7
8
# File 'lib/diaspora-cluster-creator/guarantor.rb', line 6

def initialize(attribute_name = :technology, minimum_value = 2)
  @attribute_name, @minimum_value = attribute_name, minimum_value
end

Instance Attribute Details

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



5
6
7
# File 'lib/diaspora-cluster-creator/guarantor.rb', line 5

def attribute_name
  @attribute_name
end

#minimum_valueObject (readonly)

Returns the value of attribute minimum_value.



5
6
7
# File 'lib/diaspora-cluster-creator/guarantor.rb', line 5

def minimum_value
  @minimum_value
end

Instance Method Details

#guarantee!(nodes) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/diaspora-cluster-creator/guarantor.rb', line 9

def guarantee!(nodes)
  return nodes if nodes.detect {|ss| ss.send(attribute_name) >= minimum_value }
  working = nodes.sort
  working.first.send("#{attribute_name}=", minimum_value)
  working.last.send("#{attribute_name}=", minimum_value)
  nodes
rescue NoMethodError => e
  nodes
end