Permalink
Browse files

eliminate the `loaded?` conditional

  • Loading branch information...
1 parent b93d09d commit 2075f39d726cef361170218fd16421fc52bed5a8 @tenderlove tenderlove committed Sep 24, 2013
@@ -174,14 +174,18 @@ def association_klass(reflection, record)
end
class NullPreloader
- attr_reader :owners
+ attr_reader :owners, :reflection
def initialize(klass, owners, reflection, preload_scope)
@owners = owners
+ @reflection = reflection
end
def run(preloader); end
- def loaded?; false; end
+
+ def preloaded_records
+ owners.flat_map { |owner| owner.read_attribute reflection.name }
+ end
end
def preloader_for(reflection, owners)
@@ -17,7 +17,6 @@ def initialize(klass, owners, reflection, preload_scope)
@owners_by_key = nil
@type_caster = IDENTITY_CASTER
@associated_records_by_owner = nil
- @loaded = false
end
def run(preloader)
@@ -74,15 +73,9 @@ def preloaded_records
@associated_records_by_owner.values.flatten
end
- def loaded?
- @loaded
- end
-
private
def associated_records_by_owner(preloader)
- @loaded = true
-
return @associated_records_by_owner if @associated_records_by_owner
owners_map = owners_by_key
@@ -12,8 +12,6 @@ def source_reflection
end
def associated_records_by_owner(preloader)
- @loaded = true
-
return @associated_records_by_owner if @associated_records_by_owner
preloader.preload(owners,
@@ -54,7 +52,7 @@ def associated_records_by_owner(preloader)
r.send(source_reflection.name)
}.compact
- if pl && pl.loaded?
+ if pl
loaded_records = pl.preloaded_records
i = 0
record_index = loaded_records.each_with_object({}) { |r,indexes|

0 comments on commit 2075f39

Please sign in to comment.