From 1ff1ce654e03167ea2b1bedb0d4d7967fe798da7 Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Sat, 11 May 2024 18:41:02 +0200 Subject: [PATCH] Add introspection methods --- lib/rom/factory/attribute_registry.rb | 6 ++++++ lib/rom/factory/attributes/callable.rb | 6 ++++++ lib/rom/factory/dsl.rb | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/lib/rom/factory/attribute_registry.rb b/lib/rom/factory/attribute_registry.rb index 9a5c443..24d3800 100644 --- a/lib/rom/factory/attribute_registry.rb +++ b/lib/rom/factory/attribute_registry.rb @@ -54,6 +54,12 @@ def reject(&block) self.class.new(elements.reject(&block)) end + # @api private + def inspect + "#<#{self.class} #{elements.inspect}>" + end + alias_method :to_s, :inspect + private # @api private diff --git a/lib/rom/factory/attributes/callable.rb b/lib/rom/factory/attributes/callable.rb index 0288a6c..5fe065b 100644 --- a/lib/rom/factory/attributes/callable.rb +++ b/lib/rom/factory/attributes/callable.rb @@ -28,6 +28,12 @@ def value? def dependency_names block.parameters.map(&:last) end + + # @api private + def inspect + "#<#{self.class.name} #{name} at #{block.source_location.join(":")}>" + end + alias_method :to_s, :inspect end end end diff --git a/lib/rom/factory/dsl.rb b/lib/rom/factory/dsl.rb index af70d04..481d9cb 100644 --- a/lib/rom/factory/dsl.rb +++ b/lib/rom/factory/dsl.rb @@ -171,6 +171,11 @@ def association(name, *traits, **options) _attributes << attributes::Association.new(assoc, builder, *traits, **options) end + # @api private + def inspect + "#<#{self.class} name=#{_name}>" + end + alias_method :to_s, :inspect private