Class: Diaspora::Cluster::Creator::Node

Inherits:
Object
  • Object
show all
Extended by:
DependencyInjector
Includes:
Comparable
Defined in:
lib/diaspora-cluster-creator/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, name_with_attribute_values) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
# File 'lib/diaspora-cluster-creator/node.rb', line 18

def initialize(cluster, name_with_attribute_values)
  @cluster = cluster
  @attributes = []
  yield(self) if block_given?
  cluster.attributes.each do |attribute|
    @attributes << attribute_builder.call(self,attribute)
  end
  set_name_and_attribute_values(name_with_attribute_values.to_s)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/diaspora-cluster-creator/node.rb', line 28

def method_missing(method_name, *args, &block)
  if attributes && attribute = attributes.detect {|a| a.to_sym == method_name.to_sym }
    attribute.value
  elsif attributes && attribute = attributes.detect {|a| "#{a.to_sym}=".to_sym == method_name.to_sym }
    attribute.value = args.first
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/diaspora-cluster-creator/node.rb', line 17

def attributes
  @attributes
end

#clusterObject (readonly)

Returns the value of attribute cluster.



17
18
19
# File 'lib/diaspora-cluster-creator/node.rb', line 17

def cluster
  @cluster
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/diaspora-cluster-creator/node.rb', line 17

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
# File 'lib/diaspora-cluster-creator/node.rb', line 39

def <=>(other)
  to_i <=> other.to_i
end

#labelObject



51
52
53
# File 'lib/diaspora-cluster-creator/node.rb', line 51

def label
  attributes.inject("#{name}\n") {|m,attrib| m << "#{attrib.label} "}.strip
end

#to_iObject



43
44
45
# File 'lib/diaspora-cluster-creator/node.rb', line 43

def to_i
  attributes.inject(0) {|m,v| m += v.to_i}
end

#to_sObject



47
48
49
# File 'lib/diaspora-cluster-creator/node.rb', line 47

def to_s
  name.to_s
end