Permalink
Browse files

Cache command definitions too

  • Loading branch information...
1 parent 3bfd8e4 commit ebbb95a26c3edd19e97c7c7ef882baabd60cc5c4 @rodjek committed Jun 26, 2010
Showing with 37 additions and 1 deletion.
  1. +37 −1 lib/bluster/bluster.rb
View
38 lib/bluster/bluster.rb
@@ -28,6 +28,8 @@ def contacts
# The configuration details of a contact.
#
+ # contact - The String name of the contact to lookup.
+ #
# Returns a Hash of Strings.
def get_contact(contact)
ensure_cache_up_to_date
@@ -41,6 +43,33 @@ def get_contact(contact)
data
end
+ # The list of command object names.
+ #
+ # Returns an Array of String command names.
+ def commands
+ ensure_cache_up_to_date
+ commands = self.redis.keys("bluster:objects:command:*")
+ commands.map! { |r| r.split(":")[3] }
+ commands.uniq
+ end
+
+ # The configuration details of a command.
+ #
+ # command - The String name of the command to lookup.
+ #
+ # Returns a Hash of Strings.
+ def get_command(command)
+ ensure_cache_up_to_date
+ namespace = "bluster:objects:command:#{command}"
+ keys = self.redis.keys("#{namespace}:*")
+ data = {}
+ keys.each { |key|
+ short_key = key.split(":")[4]
+ data[short_key] = self.redis.get("#{namespace}:#{short_key}")
+ }
+ data
+ end
+
private
# Checks that the provided object cache path exists.
@@ -99,7 +128,7 @@ def update_object_cache
objects[type] << data
else
chunks = line.squeeze(' ').split(' ')
- data[chunks.first] = chunks.last
+ data[chunks.first] = chunks[1..-1].join(' ')
end
end
end
@@ -112,6 +141,13 @@ def update_object_cache
}
}
+ objects["command"].each { |command|
+ namespace = "bluster:objects:command:#{command['command_name']}"
+ command.keys.each { |key|
+ self.redis.set("#{namespace}:#{key}", command[key]) if key != "command_name"
+ }
+ }
+
self.redis.set("bluster:last_update_timestamp", File.new(self.objects_path).mtime.to_i)
end
end

0 comments on commit ebbb95a

Please sign in to comment.