lib/rom/repository.rb in rom-repository-1.3.2 vs lib/rom/repository.rb in rom-repository-1.3.3
- old
+ new
@@ -80,14 +80,24 @@
# @return [Class]
defines :auto_struct
auto_struct true
+ # @!method self.auto_struct
+ # Get or set struct namespace
+ defines :struct_namespace
+
+ struct_namespace ROM::Struct
+
# @!attribute [r] container
# @return [ROM::Container] The container used to set up a repo
param :container, allow: ROM::Container
+ # @!attribute [r] struct_namespace
+ # @return [Module,Class] The namespace for auto-generated structs
+ option :struct_namespace, default: -> { self.class.struct_namespace }
+
# @!attribute [r] auto_struct
# @return [Boolean] The container used to set up a repo
option :auto_struct, default: -> { self.class.auto_struct }
# @!attribute [r] relations
@@ -109,11 +119,11 @@
#
# @api public
def initialize(container, opts = EMPTY_HASH)
super
- @mappers = MapperBuilder.new
+ @mappers = MapperBuilder.new(struct_namespace: struct_namespace)
@relations = RelationRegistry.new do |registry, relations|
self.class.relations.each do |name|
relation = container.relation(name)
@@ -270,10 +280,10 @@
# user = transaction do |t|
# create(changeset(name: 'Jane'))
# end
#
# user
- # # => #<ROM::Struct[User] id=1 name="Jane">
+ # # => #<ROM::Struct::User id=1 name="Jane">
#
# @example with a rollback
# user = transaction do |t|
# changeset(name: 'Jane').commit
# t.rollback!