lib/dry/data.rb in dry-data-0.0.1 vs lib/dry/data.rb in dry-data-0.1.0
- old
+ new
@@ -31,11 +31,18 @@
def self.container
@container ||= Container.new
end
- def self.register(name, type)
- container.register(name, type)
+ def self.register(name, type = nil, &block)
+ container.register(name, type || block.call)
+ end
+
+ def self.register_class(klass)
+ container.register(
+ Inflecto.underscore(klass).gsub('/', '.'),
+ Type.new(klass.method(:new), klass)
+ )
end
def self.[](name)
type_map.fetch(name) do
result = name.match(TYPE_SPEC_REGEX)