0
@@ -20,7 +20,7 @@ module StrokeDB
0
# when model collection item is fetched, reference followed and turned into document
0
# instance with mapping proc of lazy mapping array.
0
- class LazyMappingArray <
BlankSlate(Array)0
+ class LazyMappingArray <
Array0
@map_proc = proc {|v| v}
0
@unmap_proc = proc {|v| v}
0
@@ -37,28 +37,107 @@ module StrokeDB
0
+ alias :_square_brackets :[]
0
+ r = _square_brackets(*args)
0
+ if (args.first.is_a?(Range) || args.size == 2) && r.is_a?(Array)
0
+ LazyMappingArray.new(r).map_with(&@map_proc).unmap_with(&@unmap_proc)
0
- def method_missing sym, *args, &blk
0
- super if sym.to_s =~ /^__/
0
- mname = "__#{::BlankSlate::MethodMapping[sym.to_s] || sym}"
0
+ alias :_square_brackets_set :[]=
0
+ if (args.first.is_a?(Range) || args.size == 2) && value.is_a?(Array)
0
+ args << value.map{|e| @unmap_proc.call(e) }
0
+ _square_brackets_set(*args)
0
+ _square_brackets_set(args[0], @unmap_proc.call(value))
0
- when :push, :unshift, :<<, :[]=, :index, :-
0
- last = last.is_a?(Array) ? last.map{|v| @unmap_proc.call(v) } : @unmap_proc.call(last)
0
+ @map_proc.call(_at(index))
0
- __send__(mname, *args, &blk)
0
- when :[], :slice, :at, :map, :shift, :pop, :include?, :last, :first, :zip, :each, :inject, :each_with_index
0
- __map{|v| @map_proc.call(v) }.__send__(sym, *args, &blk)
0
- __send__(mname, *args, &blk)
0
+ yield @map_proc.call(val)
0
+ yield @map_proc.call(val)
0
+ _push(@unmap_proc.call(value))
0
+ alias :_unshift :unshift
0
+ _unshift(@unmap_proc.call(value))
0
+ @map_proc.call(_shift)
0
+ _find {|value| yield(@map_proc.call(value))}
0
+ _index(@unmap_proc.call(v))
0
+ _substract(a.map {|v| @unmap_proc.call(v) })
0
+ alias :_include? :include?
0
+ _include?(@unmap_proc.call(v))
Comments
No one has commented yet.