diff options
author | ytti <saku@ytti.fi> | 2013-10-14 02:23:22 -0700 |
---|---|---|
committer | ytti <saku@ytti.fi> | 2013-10-14 02:23:22 -0700 |
commit | d7d490077ce16e76367773f5a5fe8bca4f84f366 (patch) | |
tree | eb0b104fb3573e121bda90a10bab0af883f2e5d7 | |
parent | b19297dde99dfa2430f96ab90b9daeed2a9f340b (diff) | |
parent | fb4bc13364624bd8d78659de52bb5180c040cb0e (diff) |
Merge pull request #6 from nopedial/master
Implement fetch method for 'file' output model
-rw-r--r-- | lib/oxidized/api/rest.rb | 6 | ||||
-rw-r--r-- | lib/oxidized/nodes.rb | 6 | ||||
-rw-r--r-- | lib/oxidized/output/file.rb | 4 | ||||
-rw-r--r-- | oxidized.gemspec | 2 |
4 files changed, 17 insertions, 1 deletions
diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb index 783b445..d876917 100644 --- a/lib/oxidized/api/rest.rb +++ b/lib/oxidized/api/rest.rb @@ -41,6 +41,12 @@ module Oxidized # /nodes/show/node - returns data about node when /show\/(.*)/ send res, @nodes.show($1) + when /fetch\/(.*)/ + begin + send res, @nodes.fetch($1) + rescue Oxidized::NotSupported => e + send res, e + end end end end diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index e5e87e5..dcebe08 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -1,5 +1,6 @@ module Oxidized require 'oxidized/node' + class Oxidized::NotSupported < StandardError; end class Nodes < Array attr_accessor :source alias :put :unshift @@ -26,6 +27,11 @@ module Oxidized i = find_index node self[i].serialize if i end + def fetch node + i = find_index node + raise Oxidized::NotSupported unless Oxidized.mgr.output.respond_to? :fetch + self[i].output.new.fetch node + end def del node i = find_index node delete_at i if i diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 66ad178..8aaae0e 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -25,5 +25,9 @@ class OxFile < Output open(file, 'w') { |fh| fh.write data } end + def fetch node + IO.readlines File.join(@cfg[:directory], node) + end + end end diff --git a/oxidized.gemspec b/oxidized.gemspec index 5a1dce9..38a2e41 100644 --- a/oxidized.gemspec +++ b/oxidized.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'oxidized' - s.version = '0.0.11' + s.version = '0.0.14' s.platform = Gem::Platform::RUBY s.authors = [ 'Saku Ytti' ] s.email = %w( saku@ytti.fi ) |