Module: Neo4Apis::TableResolver
- Defined in:
- lib/neo4apis/table_resolver.rb
Defined Under Namespace
Classes: UnfoundPrimaryKeyError
Instance Method Summary
collapse
Instance Method Details
#identify_primary_key(columns, class_name) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# 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| fail UnfoundPrimaryKeyError, "Could not find a primary key for #{class_name}." if found_key.nil?
end
end
|
#identify_table_name(tables, class_name) ⇒ Object
10
11
12
13
14
15
16
17
|
# 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| puts "WARNING: Could not find a table for #{class_name}." if found_name.nil?
end
end
|