Sha256: 80cf7b4347403abc3817a27a0efbd1e4791a3cbbe7672470daa29b37e620822d

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

# frozen_string_literal: true

module Qonfig
  class DataSet
    # @api private
    # @since 0.2.0
    module ClassBuilder
      class << self
        # @param hash [Hash]
        # @return [Class<Qonfig::DataSet>]
        #
        # @see Qonfig::DataSet
        #
        # @api private
        # @since 0.2.0
        def build_from_hash(hash)
          Class.new(Qonfig::DataSet).tap do |data_set_klass|
            hash.each_pair do |key, value|
              if value.is_a?(Hash) && value.any?
                sub_data_set_klass = build_from_hash(value)
                data_set_klass.setting(key) { compose sub_data_set_klass }
              else
                data_set_klass.setting key, value
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qonfig-0.10.0 lib/qonfig/data_set/class_builder.rb
qonfig-0.9.0 lib/qonfig/data_set/class_builder.rb
qonfig-0.8.0 lib/qonfig/data_set/class_builder.rb