lib/nagios/objects.rb in ruby-nagios-0.0.2 vs lib/nagios/objects.rb in ruby-nagios-0.1.0

- old
+ new

@@ -58,29 +58,29 @@ class Objects # @param [String] path UNIX path to the objects.cache file # @see Nagios::Objects.parse def initialize path - raise "File does not exist" unless File.exist? path - raise "File is not readable" unless File.readable? path - @objects_file = path + raise "File #{path} does not exist" unless File.exist? path + raise "File #{path} is not readable" unless File.readable? path + @path = path @objects = {} end # PATH to the objects.cache file - attr_accessor :objects_file + attr_accessor :path # Parsed objects attr_accessor :objects =begin rdoc Read objects.cache file and parse it. Method reads file by blocks. Each block defines one object, definition -starts with 'define <type> {' and ends with '}'. Each block has a +starts with 'define <type> !{' and ends with '}'. Each block has a '<type>_name' line which defines name of the instance of the object. Code of the 'parse()' method assumes, that _name line is always first in the block! This can be not always the case. @@ -108,11 +108,11 @@ (i.e. nagios.objects[:host]) or convenience method: nagios.host. =end def parse block = {} - content = File.readlines objects_file + content = File.readlines path handler = nil content.each do |line| case when line =~ /^\s*$/ then next # Skip empty lines when line =~ /^\s*#/ then next # Skip comments @@ -141,11 +141,12 @@ # Basic find function for resources. # @param [Symbol] resource Resource to search from: :host, :hostgroup, etc. # @param [Symbol] attribute Attribute to use in search. For example, find host by hostname or address, etc. anything that's defined for this resource # @param [Symbol] message Is either 'find' or 'find_all' passed from caller. In case of 'find' returns 1 hash, 'find_all' - Array of Hash'es. - # @param [String] or [Regexp] pattern Search pattern + # + # @param [String, Regexp] pattern Search pattern def find resource, message, attribute, pattern self.send(resource.to_sym).values.send(message) do |a| case pattern when String @@ -164,12 +165,12 @@ # @see find # # @param [Symbol] sym Should be in the form # find(_all)?_<resource>_by_<attribute>. Similar to # ActiveResource find_* dynamic methods. Depending on the name - # of the mthod called (find or find_all) will pass message to - # self.find method, that will call {Array.find} or - # {Array.find_all} accordingly. + # of the method called (find or find_all) will pass message to + # self.find method, that will call Array#find or + # Array.find_all accordingly. # # find_*_by and find_all_*. find_all returns Array of # hashes. def method_missing sym, *args, &block