lib/arborist/node/resource.rb in arborist-0.2.0.pre20170519125456 vs lib/arborist/node/resource.rb in arborist-0.2.0
- old
+ new
@@ -25,20 +25,22 @@
### Set service +attributes+.
def modify( attributes )
attributes = stringify_keys( attributes )
- super
+ super
self.category( attributes['category'] )
end
### Return a Hash of the operational values that are included with the node's
### monitor state.
def operational_values
return super.merge(
- addresses: self.addresses.map( &:to_s )
+ addresses: self.addresses.map( &:to_s ),
+ hostname: self.hostname,
+ category: self.category
)
end
### Get/set the resource category.
@@ -52,22 +54,29 @@
def addresses
return @host.addresses
end
+ ### Delegate the resource's hostname to it's parent host.
+ def hostname
+ return @host.hostname
+ end
+
+
### Overridden to disallow modification of a Resource parent, as it needs a
### reference to the Host node for delegation.
def parent( new_parent=nil )
return super unless new_parent
raise "Can't reparent a resource; replace the node instead"
end
### Serialize the resource node. Return a Hash of the host node's state.
- def to_h
+ def to_h( * )
return super.merge(
- addresses: self.addresses.map( &:to_s )
+ addresses: self.addresses.map( &:to_s ),
+ category: self.category
)
end
### Returns +true+ if the node matches the specified +key+ and +val+ criteria.
@@ -76,10 +85,10 @@
return case key
when 'address'
search_addr = IPAddr.new( val )
self.addresses.any? {|a| search_addr.include?(a) }
when 'category'
- self.category == val
+ Array( val ).include?( self.category )
else
super
end
end