diff options
author | Saku Ytti <saku@ytti.fi> | 2013-10-25 20:39:59 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2013-10-25 20:39:59 +0300 |
commit | 4455a5b91accda5da7c1b8128cb045c7eb7bb5da (patch) | |
tree | 96764af0bcc7980c66779f7ef42e832df88982d5 | |
parent | 0060d65fb92c2e09ec04e6bccb25f53338b71d0a (diff) |
Fix fetch method
-rw-r--r-- | lib/oxidized/nodes.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index d878d89..affeea8 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -1,6 +1,7 @@ module Oxidized require 'oxidized/node' class Oxidized::NotSupported < StandardError; end + class Oxidized::NodeNotFound < StandardError; end class Nodes < Array attr_accessor :source alias :put :unshift @@ -20,21 +21,18 @@ module Oxidized def list map { |e| e.name } end - def find_index node - index { |e| e.name == node } - end def show node - i = find_index node - self[i].serialize if i + i = find_node_index node + self[i].serialize end def fetch node, group - raise Oxidized::NotSupported unless Oxidized.mgr.output.respond_to? :fetch - i = find_index node - self[i].output.new.fetch node, group + i = find_node_index node + output = self[i].output.new + raise Oxidized::NotSupported unless output.respond_to? :fetch + output.fetch node, group end def del node - i = find_index node - delete_at i if i + delete_at find_node_index end # @param node [String] name of the node moved into the head of array def next node, opt={} @@ -52,5 +50,15 @@ module Oxidized def get (self << shift).last end + + private + + def find_index node + index { |e| e.name == node } + end + + def find_node_index node + find_index node or raise Oxidized::NodeNotFound + end end end |