lib/rom/reader_builder.rb in rom-0.4.2 vs lib/rom/reader_builder.rb in rom-0.5.0
- old
+ new
@@ -1,7 +1,8 @@
-module ROM
+require 'rom/mapper_registry'
+module ROM
# @api private
class ReaderBuilder
DEFAULT_OPTIONS = { inherit_header: true }.freeze
attr_reader :relations, :readers
@@ -19,20 +20,29 @@
builder = MapperBuilder.new(name, parent, options)
builder.instance_exec(&block) if block
mapper = builder.call
- mappers = options[:parent] ? readers.fetch(parent.name).mappers : {}
+ mappers =
+ if options[:parent]
+ readers.fetch(parent.name).mappers
+ else
+ MapperRegistry.new
+ end
mappers[name] = mapper
- readers[name] = Reader.new(name, parent, mappers) unless options[:parent]
+
+ unless options[:parent]
+ readers[name] = Reader.build(
+ name, parent, mappers, parent.class.relation_methods
+ )
+ end
end
end
private
def with_options(options)
yield(DEFAULT_OPTIONS.merge(options))
end
-
end
end