Class: Arnold::Node
- Inherits:
-
Object
- Object
- Arnold::Node
- Defined in:
- lib/arnold/node.rb
Constant Summary collapse
- @@reserved_params =
['guid', 'name', 'macaddr', 'classes']
Instance Attribute Summary collapse
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#macaddr ⇒ Object
Returns the value of attribute macaddr.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
- #disabled ⇒ Object
-
#enabled ⇒ Object
returns classes and descriptions for classes enabled or disabled.
-
#initialize(guid = nil, name = nil, macaddr = nil, parameters = {}, classes = []) ⇒ Node
constructor
A new instance of Node.
-
#validate(value, type = :exists) ⇒ Object
Raise exceptions if the given condition fails.
Constructor Details
#initialize(guid = nil, name = nil, macaddr = nil, parameters = {}, classes = []) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 |
# File 'lib/arnold/node.rb', line 6 def initialize(guid=nil, name=nil, macaddr=nil, parameters={}, classes = []) # if no guid, this is intended to be a new node self.guid = guid self.name = name self.macaddr = macaddr self.parameters = parameters self.classes = classes end |
Instance Attribute Details
#classes ⇒ Object
Returns the value of attribute classes.
3 4 5 |
# File 'lib/arnold/node.rb', line 3 def classes @classes end |
#guid ⇒ Object
Returns the value of attribute guid.
3 4 5 |
# File 'lib/arnold/node.rb', line 3 def guid @guid end |
#macaddr ⇒ Object
Returns the value of attribute macaddr.
3 4 5 |
# File 'lib/arnold/node.rb', line 3 def macaddr @macaddr end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/arnold/node.rb', line 3 def name @name end |
#parameters ⇒ Object
Returns the value of attribute parameters.
3 4 5 |
# File 'lib/arnold/node.rb', line 3 def parameters @parameters end |
Class Method Details
.munge(value, type = :upcase) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/arnold/node.rb', line 77 def self.munge(value, type=:upcase) case type when :upcase return value.nil? ? nil : value.upcase when :params return value.reject { |name, val| @@reserved_params.include? name } end end |
Instance Method Details
#disabled ⇒ Object
41 42 43 44 |
# File 'lib/arnold/node.rb', line 41 def disabled return $CONFIG[:classes] if @classes.nil? $CONFIG[:classes].reject { |name, desc| @classes.include? name } end |
#enabled ⇒ Object
returns classes and descriptions for classes enabled or disabled
36 37 38 39 |
# File 'lib/arnold/node.rb', line 36 def enabled return {} if @classes.nil? $CONFIG[:classes].select { |name, desc| @classes.include? name } end |
#validate(value, type = :exists) ⇒ Object
Raise exceptions if the given condition fails
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/arnold/node.rb', line 48 def validate(value, type=:exists) case type when :classes return if value.nil? raise "Invalid type: #{value.class}" if not value.kind_of?(Array) value.each { |n| raise "Invalid class: #{n}" if not $CONFIG[:classes].has_key?(n) } when :params return if value.nil? raise "Invalid type: #{value.class}" if not value.kind_of?(Hash) @@reserved_params.each { |n| raise "Invalid parameter: #{n}" if value.has_key?(n) } when :macaddr return if value.nil? value.upcase! raise "Invalid MAC address: #{value}" if not value =~ /^(([0-9A-F]{2}[:-]){5}([0-9A-F]{2}))?$/ when :filename return if value.nil? raise "Invalid name: #{value}" if not value =~ /^([^\/])*$/ when :exists raise "Value does not exist." if (value.nil? || value.empty?) end return value end |