summaryrefslogtreecommitdiff
path: root/lib/oxidized/nodes.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2013-04-19 12:36:45 +0300
committerSaku Ytti <saku@ytti.fi>2013-04-19 12:41:29 +0300
commit96668cc2dc0367e3d1a3ec94265ce889b62d8ada (patch)
tree340f92a6dd4b68e41a946729c8fae34db7aff40b /lib/oxidized/nodes.rb
parent9d217025fac3e335c308f02e7377e14ccfdc0e66 (diff)
Add restful API
Diffstat (limited to 'lib/oxidized/nodes.rb')
-rw-r--r--lib/oxidized/nodes.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb
index 467d3a0..3e58348 100644
--- a/lib/oxidized/nodes.rb
+++ b/lib/oxidized/nodes.rb
@@ -2,7 +2,7 @@ module Oxidized
require 'oxidized/node'
class Nodes < Array
attr_accessor :source
- alias :del :delete
+ alias :put :unshift
def initialize *args
super
load if args.empty?
@@ -17,17 +17,25 @@ module Oxidized
replace new
end
def list
- self
+ map { |e| e.name }
end
- # @param node [String] name of the node inserted into nodes array
- def put node
- unshift node
+ def find_index node
+ index { |e| e.name == node }
+ end
+ def show node
+ i = find_index node
+ self[i].serialize if i
+ end
+ def del node
+ i = find_index node
+ delete_at i if i
end
# @param node [String] name of the node moved into the head of array
- def top node
+ def next node
n = del node
put n if n
end
+ alias :top :next
# @return [String] node from the head of the array
def get
(self << shift).last