diff --git a/lib/generators/vrt.rb b/lib/generators/vrt.rb index d5bcc1b..b1bab17 100644 --- a/lib/generators/vrt.rb +++ b/lib/generators/vrt.rb @@ -1,3 +1,10 @@ +# frozen_string_literal: true + +VRT.configure do |config| + # Example to return an array from `get_lineage` + # config.lineage_string_separator = nil +end + # Pre-warm the in-memory store of these class instance vars when we launch the # server. Prevents unnecessary file I/O per-request. VRT.reload! diff --git a/lib/vrt.rb b/lib/vrt.rb index e97a80f..66ea286 100644 --- a/lib/vrt.rb +++ b/lib/vrt.rb @@ -142,4 +142,16 @@ def unload! @maps = {} @mappings = nil end + + def self.configure + @configuration = VRT::Configuration.new + + yield configuration if block_given? + + configuration + end + + def self.configuration + @configuration || configure + end end diff --git a/lib/vrt/configuration.rb b/lib/vrt/configuration.rb new file mode 100644 index 0000000..0fc25f0 --- /dev/null +++ b/lib/vrt/configuration.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module VRT + class Configuration + DEFAULT_LINEAGE_SEPARATOR = ' > ' + + attr_accessor :lineage_string_separator + + private + + def initialize + @lineage_string_separator = DEFAULT_LINEAGE_SEPARATOR + end + end +end + +# Example usage: + +# ```ruby +# def get_lineage(string, max_depth: 'variant') +# @_lineages[string + max_depth] ||= construct_lineage(string, max_depth, VRT.configuration.lineage_string_separator) +# end +# # ... +# private +# # ... +# def construct_lineage(string, max_depth, string_separator: nil) +# return unless valid_identifier?(string) +# lineage = [] +# walk_node_tree(string, max_depth: max_depth) do |node| +# return unless node +# lineage << node.name +# end +# string_separator.nil? ? lineage : lineage.join(string_separator) +# end +# ```