From 0c6b85c030a4e8ed7f4708d74da0ec9add573ee9 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 17 Feb 2021 18:41:42 -0300 Subject: [PATCH] =?UTF-8?q?preparar=20MetadataFactory=20para=20poder=20lla?= =?UTF-8?q?mar=20m=C3=A9todos=20est=C3=A1ticos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/metadata_factory.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/metadata_factory.rb b/app/models/metadata_factory.rb index 8cac1c86..c33f1f18 100644 --- a/app/models/metadata_factory.rb +++ b/app/models/metadata_factory.rb @@ -2,9 +2,14 @@ # Devuelve metadatos de cierto tipo class MetadataFactory - def self.build(**args) - @@factory_cache ||= {} - @@factory_cache[args[:type]] ||= ('Metadata' + args[:type].to_s.camelcase).constantize - @@factory_cache[args[:type]].new(args) + class << self + def build(**args) + classify(args[:type]).new(**args) + end + + def classify(type) + @factory_cache ||= {} + @factory_cache[type] ||= ('Metadata' + type.to_s.camelcase).constantize + end end end