lib/rom/boot.rb in rom-0.3.0 vs lib/rom/boot.rb in rom-0.3.1
- old
+ new
@@ -6,10 +6,12 @@
# Exposes DSL for defining schema, relations and mappers
#
# @api public
class Boot
+ include Equalizer.new(:repositories, :env)
+
attr_reader :repositories, :adapter_relation_map, :env
# @api private
def initialize(repositories)
@repositories = repositories
@@ -34,10 +36,11 @@
# end
#
# @api public
def schema(&block)
@schema = DSL.new(self).schema(&block)
+ self
end
# Relation definition DSL
#
# @example
@@ -49,10 +52,11 @@
# end
#
# @api public
def relation(name, &block)
@relations.update(name => block)
+ self
end
# Mapper definition DSL
#
# @example
@@ -68,10 +72,11 @@
# end
#
# @api public
def mappers(&block)
@mappers.concat(DSL.new(self).mappers(&block))
+ self
end
# Finalize the setup
#
# @return [Env] frozen env with access to repositories, schema, relations and mappers
@@ -120,10 +125,12 @@
Schema.new(base_relations)
end
# @api private
def load_relations(schema)
+ return RelationRegistry.new unless adapter_relation_map.any?
+
builder = RelationBuilder.new(schema)
relations = @relations.each_with_object({}) do |(name, block), h|
adapter = adapter_relation_map[name]
@@ -142,16 +149,18 @@
RelationRegistry.new(relations)
end
# @api private
def load_readers(relations)
+ return ReaderRegistry.new unless adapter_relation_map.any?
+
reader_builder = ReaderBuilder.new(relations)
readers = @mappers.each_with_object({}) do |(name, options, block), h|
h[name] = reader_builder.call(name, options, &block)
end
- RelationRegistry.new(readers)
+ ReaderRegistry.new(readers)
end
end
end