From 57bc4aae5a81aa34e7360b582ba2b657c7179430 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Tue, 7 Jan 2025 11:05:39 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20multivalue=20split=20and?= =?UTF-8?q?=20join=20on=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit will move the :multi_value_element_join_on and :multi_value_element_split_on config options into the `Configuration` class. Previous, the Bulkrax initializer was not able to set these options. --- lib/bulkrax.rb | 52 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/bulkrax.rb b/lib/bulkrax.rb index 1fd9a95f..071da56f 100644 --- a/lib/bulkrax.rb +++ b/lib/bulkrax.rb @@ -39,8 +39,6 @@ class Configuration :field_mappings, :generated_metadata_mapping, :import_path, - :multi_value_element_join_on, - :multi_value_element_split_on, :object_factory, :parsers, :qa_controlled_properties, @@ -175,6 +173,33 @@ def use_locking ENV.key?("REDIS_HOST") end alias use_locking? use_locking + + DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON = ' | ' + # Specify the delimiter for joining an attribute's multi-value array into a string. + # + # @note the specific delimiter should likely be present in the multi_value_element_split_on + # expression. + def multi_value_element_join_on + @multi_value_element_join_on ||= DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON + end + + attr_writer :multi_value_element_split_on + + DEFAULT_MULTI_VALUE_ELEMENT_SPLIT_ON = /\s*[:;|]\s*/.freeze + # @return [RegexClass] the regular express to use to "split" an attribute's values. If set to + # `true` use the DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON. + # + # @note The "true" value is to preserve backwards compatibility. + # @see DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON + def multi_value_element_split_on + if @multi_value_element_split_on.is_a?(TrueClass) + DEFAULT_MULTI_VALUE_ELEMENT_SPLIT_ON + else + @multi_value_element_split_on ||= DEFAULT_MULTI_VALUE_ELEMENT_SPLIT_ON + end + end + + attr_writer :multi_value_element_join_on end def config @@ -361,29 +386,6 @@ def api_definition ) end - DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON = ' | ' - # Specify the delimiter for joining an attribute's multi-value array into a string. - # - # @note the specific delimiter should likely be present in the multi_value_element_split_on - # expression. - def multi_value_element_join_on - @multi_value_element_join_on ||= DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON - end - - DEFAULT_MULTI_VALUE_ELEMENT_SPLIT_ON = /\s*[:;|]\s*/.freeze - # @return [RegexClass] the regular express to use to "split" an attribute's values. If set to - # `true` use the DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON. - # - # @note The "true" value is to preserve backwards compatibility. - # @see DEFAULT_MULTI_VALUE_ELEMENT_JOIN_ON - def multi_value_element_split_on - if @multi_value_element_join_on.is_a?(TrueClass) - DEFAULT_MULTI_VALUE_ELEMENT_SPLIT_ON - else - @multi_value_element_split_on ||= DEFAULT_MULTI_VALUE_ELEMENT_SPLIT_ON - end - end - # Responsible for stripping hidden characters from the given string. # # @param value [#to_s]