Sha256: 53cb524a80e462c7377952662782b0bf45f287a19cec1426f793a332b8de38ff

Contents?: true

Size: 718 Bytes

Versions: 80

Compression:

Stored size: 718 Bytes

Contents

require "yaml"

module Standard
  module Performance
    class LoadsYamlWithInheritance
      def load(path)
        yaml = YAML.load_file(path)
        if (parent_path = yaml.delete("inherit_from"))
          base_path = File.dirname(path)
          parent_yaml = load(File.join(base_path, parent_path))

          two_layer_merge(parent_yaml, yaml)
        else
          yaml
        end
      end

      private

      def two_layer_merge(parent, base)
        parent.merge(base) do |key, parent_value, base_value|
          if parent_value.is_a?(Hash) && base_value.is_a?(Hash)
            parent_value.merge(base_value)
          else
            base_value
          end
        end
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 3 rubygems

Version Path
standard-performance-1.6.0 lib/standard/performance/loads_yaml_with_inheritance.rb
standard-performance-1.5.0 lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
standard-performance-1.3.1 lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/standard-performance-1.2.1/lib/standard/performance/loads_yaml_with_inheritance.rb