lib/rom/repository/struct_builder.rb in rom-repository-1.1.0 vs lib/rom/repository/struct_builder.rb in rom-repository-1.2.0
- old
+ new
@@ -1,10 +1,11 @@
require 'dry/core/inflector'
require 'dry/core/cache'
require 'dry/core/class_builder'
require 'rom/struct'
+require 'rom/open_struct'
require 'rom/schema/attribute'
module ROM
class Repository
# @api private
@@ -14,12 +15,16 @@
def call(*args)
fetch_or_store(*args) do
name, header = args
attributes = visit(header).compact
- build_class(name, ROM::Struct) do |klass|
- attributes.each do |(name, type)|
- klass.attribute(name, type)
+ if attributes.empty?
+ ROM::OpenStruct
+ else
+ build_class(name, ROM::Struct) do |klass|
+ attributes.each do |(name, type)|
+ klass.attribute(name, type)
+ end
end
end
end
end
alias_method :[], :call