class ThingTank

TODO: character validator

Public Instance Methods

character_view_by(klass, *keys) click to toggle source
# File lib/thingtank/thingtank.rb, line 10
def character_view_by(klass, *keys)
  opts = keys.pop if keys.last.is_a?(Hash)
  opts ||= {}
  opts[:guards] ||= []
  # there is no "inArray" like function in couchdb, see http://stackoverflow.com/questions/3740464/i-have-to-write-every-function-i-need-for-couchdb
  opts[:guards] << "((doc['characters'] !== undefined) && (function (item,arr) { for(p=0;p<arr.length;p++) if (item == arr[p]) return true; return false;})('#{klass.to_s}',doc['characters']))"
  keys << opts
  view_by(*keys)
end