Sha256: cab46780d0bf960082a3335fe9d101bd42ceff34533a47dfe783e941a20d1aa3

Contents?: true

Size: 1.08 KB

Versions: 34

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Entries
    class KeysConstantsSet
      common_constructor :entries_provider_class, :prefix, :suffixes

      # @return [Array<String>]
      def result
        if suffixes.is_a?(::Hash)
          keys_consts_set_from_hash
        elsif suffixes.is_a?(::Enumerable)
          keys_consts_set_from_enum
        else
          raise "Unmapped suffixes class: #{suffixes.class}"
        end
      end

      private

      # @return [String]
      def key_const_set(prefix, suffix)
        key = [prefix, suffix].compact_blank.join('.')
        entries_provider_class.const_set(key.gsub('.', '_').upcase, key)
        key
      end

      # @return [Array<String>]
      def keys_consts_set_from_enum
        suffixes.map { |suffix| key_const_set(prefix, suffix) }
      end

      # @return [Array<String>]
      def keys_consts_set_from_hash
        suffixes.flat_map do |k, v|
          self.class.new(entries_provider_class, prefix.to_s + (k.blank? ? '' : ".#{k}"), v).result
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
avm-0.94.1 lib/avm/entries/keys_constants_set.rb
eac_tools-0.98.0 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.94.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.94.0 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.93.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.92.0 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.92.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.91.0 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.90.1 lib/avm/entries/keys_constants_set.rb
eac_tools-0.87.1 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.90.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.87.0 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.89.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.86.12 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.88.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.86.11 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.87.0 lib/avm/entries/keys_constants_set.rb
eac_tools-0.86.8 sub/avm/lib/avm/entries/keys_constants_set.rb
avm-0.86.2 lib/avm/entries/keys_constants_set.rb
eac_tools-0.86.7 sub/avm/lib/avm/entries/keys_constants_set.rb