Module: GraphitiGql::ActiveRecordAdapterExtras

Extended by:
ActiveSupport::Concern
Defined in:
lib/graphiti_gql/graphiti_hax.rb

Instance Method Summary collapse

Instance Method Details

#filter_string_eq(scope, attribute, value, is_not: false) ⇒ Object



431
432
433
434
435
436
437
438
439
440
# File 'lib/graphiti_gql/graphiti_hax.rb', line 431

def filter_string_eq(scope, attribute, value, is_not: false)
  if mysql?(scope)
    clause = { attribute => value }
    is_not ? scope.where.not(clause) : scope.where(clause)
  else
    # og behavior
    column = column_for(scope, attribute)
    clause = column.lower.eq_any(value.map(&:downcase))
  end
end

#filter_string_eql(scope, attribute, value, is_not: false) ⇒ Object



442
443
444
445
446
447
448
449
# File 'lib/graphiti_gql/graphiti_hax.rb', line 442

def filter_string_eql(scope, attribute, value, is_not: false)
  if mysql?(scope)
    value = "BINARY #{value}"
  end
  # og behavior
  clause = {attribute => value}
  is_not ? scope.where.not(clause) : scope.where(clause)
end

#mysql?(scope) ⇒ Boolean

TODO: integration specs mysql vs postgres for case sensitivity

Returns:

  • (Boolean)


426
427
428
429
# File 'lib/graphiti_gql/graphiti_hax.rb', line 426

def mysql?(scope)
  mysql = ActiveRecord::ConnectionAdapters::Mysql2Adapter
  scope.model.connection.is_a?(mysql)
end

#sanitized_like_for(scope, attribute, value, &block) ⇒ Object



451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/graphiti_gql/graphiti_hax.rb', line 451

def sanitized_like_for(scope, attribute, value, &block)
  escape_char = "\\"
  column = column_for(scope, attribute)
  map = value.map { |v|
    v = v.downcase unless mysql?(scope)
    v = Graphiti::Adapters::ActiveRecord::Sanitizer.sanitize_like(v, escape_char)
    block.call v
  }
  arel = column
  arel = arel.lower unless mysql?(scope)
  arel.matches_any(map, escape_char, true)
end