class Telepath::Handler
Public Class Methods
new(command)
click to toggle source
# File lib/telepath/handler.rb, line 3 def initialize command @command = command end
Public Instance Methods
add(value, name = 'stack')
click to toggle source
# File lib/telepath/handler.rb, line 7 def add value, name = 'stack' with_store name do |container| container << value end end
index(*indicies)
click to toggle source
# File lib/telepath/handler.rb, line 31 def index *indicies with_store 'stack' do |container| indicies.map do |index| container[-(index.to_i + 1)] end end end
last(count = nil)
click to toggle source
# File lib/telepath/handler.rb, line 13 def last count = nil with_store 'stack' do |container| if count.nil? then container.last else container.last count end end end
list(*containers)
click to toggle source
# File lib/telepath/handler.rb, line 39 def list *containers c = containers.first if c then with_store c do |container| rev_array container end else rev_array storage.store.adapter.backend.keys end end
lookup(pattern)
click to toggle source
# File lib/telepath/handler.rb, line 23 def lookup pattern with_store 'stack' do |container| container.find do |element| /#{pattern}/ =~ element.to_s end end end
storage()
click to toggle source
# File lib/telepath/handler.rb, line 51 def storage if @storage && @storage.ready? then @storage else @storage = Telepath::Storage.new end end
Protected Instance Methods
present?(value)
click to toggle source
# File lib/telepath/handler.rb, line 76 def present? value !!value && ((value.respond_to?(:empty?) || true) && !value.empty?) end
rev_array(list_of_things)
click to toggle source
# File lib/telepath/handler.rb, line 61 def rev_array list_of_things Array(list_of_things).reverse end
with_store(name = 'stack') { |container| ... }
click to toggle source
# File lib/telepath/handler.rb, line 65 def with_store name = 'stack' container = storage.store[name] || Array.new result = yield container storage.store[name] = container if present? container result ensure storage.store.close end