diff options
-rw-r--r-- | lib/leap_cli/config/object_list.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/leap_cli/config/object_list.rb b/lib/leap_cli/config/object_list.rb index ebb0bb0..830e96d 100644 --- a/lib/leap_cli/config/object_list.rb +++ b/lib/leap_cli/config/object_list.rb @@ -64,6 +64,12 @@ module LeapCli end end + def exclude(node) + list = self.dup + list.delete(node.name) + return list + end + def each_node(&block) self.keys.sort.each do |node_name| yield self[node_name] @@ -108,6 +114,49 @@ module LeapCli end # + # pick_fields(field1, field2, ...) + # + # generates a Hash from the object list, but with only the fields that are picked. + # + # If there are more than one field, then the result is a Hash of Hashes. + # If there is just one field, it is a simple map to the value. + # + # For example: + # + # "neighbors" = "= nodes_like_me[:services => :couchdb].pick_fields('domain.full', 'ip_address')" + # + # generates this: + # + # neighbors: + # couch1: + # domain_full: couch1.bitmask.net + # ip_address: "10.5.5.44" + # couch2: + # domain_full: couch2.bitmask.net + # ip_address: "10.5.5.52" + # + # But this: + # + # "neighbors": "= nodes_like_me[:services => :couchdb].pick_fields('domain.full')" + # + # will generate this: + # + # neighbors: + # couch1: couch1.bitmask.net + # couch2: couch2.bitmask.net + # + def pick_fields(*fields) + self.values.inject({}) do |hsh, node| + value = self[node.name].pick(*fields) + if fields.size == 1 + value = value.values.first + end + hsh[node.name] = value + hsh + end + end + + # # applies inherit_from! to all objects. # def inherit_from!(object_list) |