module Neo4Apis::TableResolver
Public Instance Methods
identify_primary_key(columns, class_name)
click to toggle source
# File lib/neo4apis/table_resolver.rb, line 19 def identify_primary_key(columns, class_name) (columns & %w(id uuid)).first columns.detect do |column| case standardize(column) when 'id', 'uuid', /#{standardize(class_name.singularize)}id/, /#{standardize(class_name.pluralize)}id/ true end end.tap do |found_key| # rubocop:disable Style/MultilineBlockChain fail UnfoundPrimaryKeyError, "Could not find a primary key for #{class_name}." if found_key.nil? end end
identify_table_name(tables, class_name)
click to toggle source
# File lib/neo4apis/table_resolver.rb, line 10 def identify_table_name(tables, class_name) potential_table_comparisons = [class_name.tableize, class_name.tableize.singularize].map(&method(:standardize)) tables.detect do |table_name| potential_table_comparisons.include?(standardize(table_name)) end.tap do |found_name| # rubocop:disable Style/MultilineBlockChain puts "WARNING: Could not find a table for #{class_name}." if found_name.nil? end end
Private Instance Methods
standardize(string)
click to toggle source
# File lib/neo4apis/table_resolver.rb, line 33 def standardize(string) string.downcase.gsub(/[ _]+/, '') end