Sha256: 5e284a6bc9279338511d6cb6d47f18b19b95017faf7f4516208c86566707c1a7
Contents?: true
Size: 1.67 KB
Versions: 1
Compression:
Stored size: 1.67 KB
Contents
class Heliodor::Query private def _gen @dat = [] end def _filter(&_block) dat = [] @dat.each do |item| dat << item if yield(item) end @dat = dat end def _select(dat = {}) out = [] @dat.each do |item| out << item if (v.class == Hash) && (item >= dat) end @dat = out end def _update(dat1 = {}, dat2 = {}) @dat.each_with_index do |v, k| @dat[k] = v.merge(dat2) if (v.class == Hash) && (v >= dat1) end end def _map(&_block) @dat.each_with_index do |v, k| @dat[k] = yield(v) end end def _reduce(&_block) @dat = [@dat.reduce(&block)] end def _insert(dat) dat.each do |d| @dat << d end end def _rename(to) @full[to] = @dat @full.delete(@table) @table = to @dat = @full[@table] end def _delete @full.delete @table @db.write(@full) @dat = nil end def _write @full[@table] = @dat @db.write(@full) end def _process actions.each do |action| case action['type'] when 'create' _gen when 'ensure' _gen unless @dat when 'filter' _filter(&action['block']) when 'select' _select(action['dat']) when 'update' _update(action['dat1'], action['dat2']) when 'map' _map(&action['block']) when 'reduce' _reduce(&action['block']) when 'insert' _insert(action['data']) when 'rename' _rename(action['to']) when 'delete' _delete when 'write' _write else raise NotImplementedError, "Action `#{action['type']}` is not yet implemented!" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
heliodor-0.1.0 | lib/heliodor/query_internal.rb |