class DtkCommon::DSL::FileParser::ComponentModuleRefs::V1

Constants

OutputArrayToParseHashCols

Public Instance Methods

generate_hash(output_array) click to toggle source
# File lib/dsl/file_parser/file_types/component_module_refs/v1/component_module_refs.rb, line 57
def generate_hash(output_array)
  component_modules = output_array.inject(Hash.new) do |h,r|
    unless cmp_module = r[:component_module]
      raise Error.new("Missing field (:component_module)")
    end
    h.merge(cmp_module => Aux.hash_subset(r,OutputArrayToParseHashCols,:no_non_nil => true))
  end
  {:component_modules => component_modules}
end
parse_hash_content(input_hash) click to toggle source
# File lib/dsl/file_parser/file_types/component_module_refs/v1/component_module_refs.rb, line 21
def parse_hash_content(input_hash)
  ret = OutputArray.new
  component_modules = input_hash[:component_modules]
  if component_modules.empty?
    return ret
  end

  component_modules.each do |component_module,v|
    new_el = OutputHash.new(:component_module => component_module)
    parse_error = true
    if v.kind_of?(InputHash) and v.only_has_keys?(:version,:remote_namespace,:namespace,:external_ref) and not v.empty?()
      parse_error = false

      namespace    = v[:namespace]
      namespace    = v[:remote_namespace] if namespace.empty? # TODO: for legacy

      # to extend module_refs.yaml attributes add code here
      new_el.merge_non_empty!(:version_info => v[:version])
      new_el.merge_non_empty!(:remote_namespace => namespace)
      new_el.merge_non_empty!(:external_ref => v[:external_ref])
    elsif v.kind_of?(String)
      parse_error = false
      new_el.merge_non_empty!(:version_info => v)
    elsif v.nil?
      parse_error = false
    end
    if parse_error
      err_msg = (parse_error.kind_of?(String) ? parse_error : "Ill-formed term (#{v.inspect})")
      raise ErrorUsage::DTKParse.new(err_msg)
    else
      ret << new_el
    end
  end
  ret
end