lib/bhm/utils.rb
# Take a hash which includes Bhm::Validation & traverse upward nested module which also includes Validation
Take a hash which includes Bhm::Validation & traverse upward nested module which also includes Validation
Take a hash which includes Bhm :: Validation & traverse upward nested module which also includes Validation
def traverse_ancestors(hash)
      all = hash.singleton_class.included_modules.select { |mod| mod.include? Validation }
      current = all.first
      traversed_ancestors = []
      while current.include?(Validation)
        as_ary = current.to_s.split("::")
        accessed_key = as_ary[-1]
        transformed_key = -> do
          hack = {}.extend(current)
          key_casing = hack.default_key_case
          key_type = hack.default_key_type
          transform_module_casing(accessed_key, key_casing, key_type)
        end.call
        traversed_ancestors << transformed_key
        last = current
        current = Object.const_get(as_ary[0, (as_ary.length - 1)].join("::"))
      end
      [traversed_ancestors, last]
    end
def traverse_ancestors ( hash ) all = hash . singleton_class . included_modules . select { | mod | mod . include? Validation } current = all . first traversed_ancestors = [ ] while current . include? ( Validation ) as_ary = current . to_s . split ( "::" ) accessed_key = as_ary [ - 1 ] transformed_key = -> do hack = { } . extend ( current ) key_casing = hack . default_key_case key_type = hack . default_key_type transform_module_casing ( accessed_key , key_casing , key_type ) end . call traversed_ancestors << transformed_key last = current current = Object . const_get ( as_ary [ 0 , ( as_ary . length - 1 ) ] . join ( "::" ) ) end [ traversed_ancestors , last ] end
Take a hash which includes Bhm::Validation & traverse upward nested module which also includes Validation
Take a hash which includes Bhm :: Validation & traverse upward nested module which also includes Validation
# Truncating the final ::(string), then rejoin # Now that we have the module in question, transform the case using the module's method, if it has it defined # HACK: make an instance which extends the current module to use its #default_key values # Array # idx 0 is an array of the module names as formatted strings # idx 1 is the apex, highest "entry" module
hash
<not_specific>