<commit_before>/*jshint laxcomma: true, smarttabs: true, node: true, unused: true */
'use strict';
/**
 * A resource instance using rethinkdb via thinky as a data source
 * @module tastypie/lib/resource/rethink
 * @author <NAME>
 * @since 0.3.2
 * @requires util
 * @requires joi
 * @requires debug
 * @requires mout/lang/isNumber
 * @requires mout/lang/toArray
 * @requires mout/lang/merge
 * @requires tastypie/lib/class
 * @requires tastypie/lib/options
 * @requires tastypie/lib/http
 * @requires tastypie/lib/resource
 */

var isNumber      = require('mout/lang/isNumber')
  , isString      = require('mout/lang/isString')
  , toArray       = require('mout/lang/toArray')
  , Boom          = require( 'boom' )
  , async         = require('async')
  , typecast      = require('mout/string/typecast')
  , Class         = require('tastypie/lib/class')
  , Options       = require('tastypie/lib/class/options')
  , Resource      = require('tastypie/lib/resource')
  , Paginator     = require('tastypie/lib/paginator')
  , http          = require('tastypie/lib/http')
  , constants     = require('tastypie/lib/constants')
  , debug         = require( 'debug' )('tastypie:resource:rethink')
  , SEP           = '__'
  , orderExp      = /^(\-)?([\w]+)/
  , RethinkResource
  , terms
  ;


function toField( r, field ){
	field = field.split( SEP );
	var ret = r.row( field.shift() );
	while( field.length ){
		ret = ret( field.shift() );
	}
	return ret;
}


terms = {
	'gt'            : { value: function( r, field, term ){ return toField(r, field).gt( term ); } }
	, 'gte'         : { value: function( r, field, term ){ return toField(r, field ).ge( term ); } }
	, 'lt'          : { value: function( r, field, term ){ return toField(r, field ).lt( term ); } }
	, 'lte'         : { value: function( r, field, term ){ return toField(r, field ).le( term ); } }
	, 'ne'          : { value: function( r, field, term ){ return toField(r, field ).ne( term ); } }
	, 'nin'         : { value: function( r, field, term ){ return terms.in( r, field, term ).not(); } }
	, 'size'        : { value: function( r, field, term ){ return toField(r, field ).count().eq( term ); } }
	, 'match'       : { value: function( r, field, term ){ return toField(r, field ).contains( term ); } }
	, 'exact'       : { value: function( r, field, term ){ return toField(r, field ).eq( term ); } } 
	, 'regex'       : { value: function( r, field, term ){ return toField(r, term ).match( term ); } }
	, 'iexact'      : { value: function( r, field, term ){ return toField(r, field ).match( "(?i)" + term); } }
	, 'contains'    : { value: function( r, field, term ){ return toField(r, field ).match( term ); } }
	, 'icontains'   : { value: function( r, field, term ){ return toField(r, field ).match( "(?i)" + term ); } }
	, 'startswith'  : { value: function( r, field, term ){ return toField(r, field ).match("^" + term ); } }
	, 'istartswith' : { value: function( r, field, term ){ return toField(r, field ).match( "(?i)^" + term ); } }
	, 'endswith'    : { value: function( r, field, term ){ return toField(r, field ).match( term + "$"); } }
	, 'iendswith'   : { value: function( r, field, term ){ return toField(r, field ).match("(?i)" + term + "$"); } }

	, 'in'          : { 
		value: function( r, field, term ){
			term = isString( term ) ? term.split(',') : term;
			var filter = r.row( field ).contains( term.shift() );
			while( term.length ){
				filter = filter.or( r.row( field ).contains( term )   );
			}
			return filter;
		}
	}
	, 'all'         : {
		value: function( r, field, term ){
			term = isString( term ) ? term.split(',') : term;
			var filter = r.row( field ).contains( term.shift() );
			while( term.length ){
				filter = filter.and( r.row( field ).contains( term )   );
			}
			return filter;
		}
	}
};

/**
 * @alias module:tastypie/lib/resource/rethink
 * @constructor
 * @param {Object} options
 * @param {String} [options.pk=id] property to be considered the primary key field of the associated model
 * @extends module:tastypie/lib/resource
 * @example
var SampleResource = new Class({
	inherits:RethinkResource
	,options:{
		queryset: Sample.filter({})
	}
	,fields:{
		age:{type:'integer', null:true, attribute:'age'}
	}
});
 */
module.exports = RethinkResource = new Class({
	inherits:Resource
	,mixin:[Options]
	,options:{<commit_msg>fix the in and all filters to consume terms<commit_after>/*jshint laxcomma: true, smarttabs: true, node: true, unused: true */
'use strict';
/**
 * A resource instance using rethinkdb via thinky as a data source
 * @module tastypie/lib/resource/rethink
 * @author <NAME>
 * @since 0.3.2
 * @requires util
 * @requires joi
 * @requires debug
 * @requires mout/lang/isNumber
 * @requires mout/lang/toArray
 * @requires mout/lang/merge
 * @requires tastypie/lib/class
 * @requires tastypie/lib/options
 * @requires tastypie/lib/http
 * @requires tastypie/lib/resource
 */

var isNumber      = require('mout/lang/isNumber')
  , isString      = require('mout/lang/isString')
  , toArray       = require('mout/lang/toArray')
  , Boom          = require( 'boom' )
  , async         = require('async')
  , typecast      = require('mout/string/typecast')
  , Class         = require('tastypie/lib/class')
  , Options       = require('tastypie/lib/class/options')
  , Resource      = require('tastypie/lib/resource')
  , Paginator     = require('tastypie/lib/paginator')
  , http          = require('tastypie/lib/http')
  , constants     = require('tastypie/lib/constants')
  , debug         = require( 'debug' )('tastypie:resource:rethink')
  , SEP           = '__'
  , orderExp      = /^(\-)?([\w]+)/
  , RethinkResource
  , terms
  ;


function toField( r, field ){
	field = field.split( SEP );
	var ret = r.row( field.shift() );
	while( field.length ){
		ret = ret( field.shift() );
	}
	return ret;
}


terms = {
	'gt'            : { value: function( r, field, term ){ return toField(r, field).gt( term ); } }
	, 'gte'         : { value: function( r, field, term ){ return toField(r, field ).ge( term ); } }
	, 'lt'          : { value: function( r, field, term ){ return toField(r, field ).lt( term ); } }
	, 'lte'         : { value: function( r, field, term ){ return toField(r, field ).le( term ); } }
	, 'ne'          : { value: function( r, field, term ){ return toField(r, field ).ne( term ); } }
	, 'nin'         : { value: function( r, field, term ){ return terms.in( r, field, term ).not(); } }
	, 'size'        : { value: function( r, field, term ){ return toField(r, field ).count().eq( term ); } }
	, 'match'       : { value: function( r, field, term ){ return toField(r, field ).contains( term ); } }
	, 'exact'       : { value: function( r, field, term ){ return toField(r, field ).eq( term ); } } 
	, 'regex'       : { value: function( r, field, term ){ return toField(r, term ).match( term ); } }
	, 'iexact'      : { value: function( r, field, term ){ return toField(r, field ).match( "(?i)" + term); } }
	, 'contains'    : { value: function( r, field, term ){ return toField(r, field ).match( term ); } }
	, 'icontains'   : { value: function( r, field, term ){ return toField(r, field ).match( "(?i)" + term ); } }
	, 'startswith'  : { value: function( r, field, term ){ return toField(r, field ).match("^" + term ); } }
	, 'istartswith' : { value: function( r, field, term ){ return toField(r, field ).match( "(?i)^" + term ); } }
	, 'endswith'    : { value: function( r, field, term ){ return toField(r, field ).match( term + "$"); } }
	, 'iendswith'   : { value: function( r, field, term ){ return toField(r, field ).match("(?i)" + term + "$"); } }

	, 'in'          : { 
		value: function( r, field, term ){
			term = isString( term ) ? term.split(',') : term;
			var filter = r.row( field ).contains( term.shift() );
			while( term.length ){
				filter = filter.or( r.row( field ).contains( term.shift() ) );
			}
			return filter;
		}
	}
	, 'all'         : {
		value: function( r, field, term ){
			term = isString( term ) ? term.split(',') : term;
			var filter = r.row( field ).contains( term.shift() );
			while( term.length ){
				filter = filter.and( r.row( field ).contains( term.shift() ) );
			}
			return filter;
		}
	}
};

/**
 * @alias module:tastypie/lib/resource/rethink
 * @constructor
 * @param {Object} options
 * @param {String} [options.pk=id] property to be considered the primary key field of the associated model
 * @extends module:tastypie/lib/resource
 * @example
var SampleResource = new Class({
	inherits:RethinkResource
	,options:{
		queryset: Sample.filter({})
	}
	,fields:{
		age:{type:'integer', null:true, attribute:'age'}
	}
});
 */
module.exports = RethinkResource = new Class({
	inherits:Resource
	,mixin:[Options]
	,options:{
{'fraction_non_alphanumeric': 0.18369690011481057, 'fraction_numerical': 0.0006888633754305396, 'mean_word_length': 3.0013780431786863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3909913', 'n_tokens_mistral': 3099, 'n_tokens_neox': 2988, 'n_words': 785}