- Fixed bug: Pluralization of association name is inverted.

- Refactoring: Usage of each_with_object to cleanup code.
- Refactoring: Improved logging for association extraction.
This commit is contained in:
Thorsten Eckel 2017-08-30 17:12:28 +02:00
parent 4aae89b2b0
commit 6812c581c6

View file

@ -12,14 +12,18 @@ class Sequencer
def process
state.provide(:associations) do
associations.collect do |association|
logger.debug("Checking association '#{association}'")
next if !mapped.key?(association)
# remove from the mapped values if it's an association
value = mapped.delete(association)
logger.debug("Extracted association '#{association}' value '#{value.inspect}'")
# skip if we don't track them
next if tracked_associations.exclude?(association)
logger.debug("Using value of association '#{association}'")
[association, value]
end.compact.to_h
end
@ -29,9 +33,8 @@ class Sequencer
def associations
@associations ||= begin
associations = []
# loop over all reflections
model_class.reflect_on_all_associations.each do |reflection|
model_class.reflect_on_all_associations.each_with_object([]) do |reflection, associations|
# refection name is something like groups or organization (singular/plural)
associations.push(reflection.name)
@ -41,14 +44,13 @@ class Sequencer
# add trailing 's' to get pluralized key
reflection_name = reflection.name.to_s
if reflection_name.singularize == reflection_name
if reflection_name.singularize != reflection_name
key = "#{key}s"
end
# store _id/_ids name
associations.push(key.to_sym)
end
associations
end
end