lib/key_tree.rb in key_tree-0.5.3 vs lib/key_tree.rb in key_tree-0.6.0

- old
+ new

@@ -1,9 +1,11 @@ -require 'key_tree/version' -require 'key_tree/tree' +# frozen_string_literal: true + require 'key_tree/forest' require 'key_tree/loader' +require 'key_tree/refinements' +require 'key_tree/tree' # Manage a tree of keys # # Example: # kt=KeyTree[a: 1, b: { c: 2 }] @@ -11,21 +13,14 @@ # -> 1 # kt["b.c"] # -> 2 # module KeyTree + using Refinements + def self.[](contents = {}) - case contents - when Tree, Forest - contents - when Hash - Tree[contents] - when Array - Forest[*contents] - else - raise ArgumentError, "can't load #{contents.class} into a KeyTree" - end + contents.to_key_wood end # Load a KeyTree from some external serialization # # load +type+: +serialization+ @@ -47,10 +42,10 @@ type = type.to_sym unless type.nil? loader = Loader[type] contents = loader.load(serialization) contents = { prefix => contents } unless prefix.nil? - self[contents].with_meta_data do |meta_data| + contents.to_key_wood.with_meta_data do |meta_data| meta_data << { load: { type: type, loader: loader } } meta_data << { load: { prefix: prefix } } unless prefix.nil? end end