Class: Diaspora::Cluster::Creator::Node
- Inherits:
-
Object
- Object
- Diaspora::Cluster::Creator::Node
- Extended by:
- DependencyInjector
- Includes:
- Comparable
- Defined in:
- lib/diaspora-cluster-creator/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(cluster, name_with_attribute_values) {|_self| ... } ⇒ Node
constructor
A new instance of Node.
- #label ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(cluster, name_with_attribute_values) {|_self| ... } ⇒ Node
Returns a new instance of Node.
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
17 18 19 |
# File 'lib/diaspora-cluster-creator/node.rb', line 17 def attributes @attributes end |
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
17 18 19 |
# File 'lib/diaspora-cluster-creator/node.rb', line 17 def cluster @cluster end |
#name ⇒ Object (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 |
#label ⇒ Object
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_i ⇒ Object
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_s ⇒ Object
47 48 49 |
# File 'lib/diaspora-cluster-creator/node.rb', line 47 def to_s name.to_s end |