class Morel::SortedWindow

Public Class Methods

new(params) click to toggle source
# File lib/morel/sorted_window.rb, line 132
def initialize params
  @collection = params[:collection]
  @size       = params[:size]
  @block      = params[:block]
end

Public Instance Methods

Node(k,v) click to toggle source

list node for our linked list of key value pairs

# File lib/morel/sorted_window.rb, line 18
def Node k,v
  @next = nil
  @prev = nil
  @k    = k
  @v    = v
end
each_top() { |m;| ... } click to toggle source
# File lib/morel/sorted_window.rb, line 138
def each_top
  unless @map
    @map = Ruby2Js.new.process(@@code.to_code(@collection)).gsub(/window\(\)/,'window').gsub(/Node\(k, v\){/,'function Node(k, v){').gsub(/:max/,'max')
    @collection.db.add_stored_function('hello',@map)
    @map = "hello(this._id,this);"
  end
  reduce = "function(k,vals){ return 1; }"
  testing = @collection.collection.map_reduce(@map, reduce, :out => 'testing', :scope => { :window => nil, :max => @size }) #, :out => "testing", :query => { :user => user })
  testing.find.map{ |m| yield m; m }
end