Class: Rutty::Node

Inherits:
Config show all
Defined in:
lib/rutty/node.rb

Overview

A wrapper class representing an individual node. Normally contained by Nodes.

See Also:

Author:

  • Josh Lindsey

Since:

  • 2.0.0

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Config

#[], #[]=, #method_missing, #to_hash, #update!

Constructor Details

#initialize(data, defaults = {}) ⇒ Node

Initialize a new Rutty::Node instance by merging the user-provided data with the configured defaults.

Parameters:

  • data (Hash)

    The data provided by the user

  • defaults (Hash) (defaults to: {})

    The defaults data provided by the Config class

See Also:

Since:

  • 2.0.0



31
32
33
34
# File 'lib/rutty/node.rb', line 31

def initialize data, defaults = {}
  merged_data = defaults.merge data
  super merged_data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rutty::Config

Class Method Details

.load_config(dir) ⇒ void

Override the inherited Config.load_config method, raising an exception to indicate improper usage.

Raises:

  • (RuntimeError)

    On call, as this class has no use for this method

Since:

  • 2.3.3



19
20
21
# File 'lib/rutty/node.rb', line 19

def load_config dir
  raise "Unable to call load_config on Node objects."
end

Instance Method Details

#<=>(other) ⇒ Integer

Relation of this Rutty::Node to another Rutty::Node. Used for sorting. Compares the host property of the nodes, as it’s the only property guaranteed to be set and unique.

Parameters:

Returns:

  • (Integer)

    Relation of self to other: -1 for less-than, 0 for equal-to, 1 for greater-than

See Also:

Since:

  • 2.0.0



53
54
55
# File 'lib/rutty/node.rb', line 53

def <=> other
  self.host <=> other.host
end

#==(other) ⇒ Boolean

Checks for object eqality. Checks each property of this Rutty::Node against the other.

Parameters:

Returns:

  • (Boolean)

Since:

  • 2.0.0



62
63
64
65
66
67
68
# File 'lib/rutty/node.rb', line 62

def == other
  self.host == other.host and
  self.port == other.port and
  self.user == other.user and
  self.keypath == other.keypath and
  self.tags == other.tags
end

#has_tag?(tag) ⇒ Boolean

Whether this object’s tags array includes the specified tag.

Parameters:

  • tag (String)

    The tag string to check for

Returns:

  • (Boolean)

Since:

  • 2.0.0



40
41
42
43
# File 'lib/rutty/node.rb', line 40

def has_tag? tag
  return false if self.tags.nil? 
  self.tags.include? tag
end