Class: DtkCommon::DSL::FileParser::ComponentModuleRefs::V1

Inherits:
DtkCommon::DSL::FileParser::ComponentModuleRefs show all
Defined in:
lib/dsl/file_parser/file_types/component_module_refs/v1/component_module_refs.rb

Constant Summary collapse

OutputArrayToParseHashCols =
[{:version_info => :version},:remote_namespace]

Instance Method Summary collapse

Methods inherited from DtkCommon::DSL::FileParser

generate_hash, implements_method?, #initialize, parse_content, #parse_hash_content_aux

Constructor Details

This class inherits a constructor from DtkCommon::DSL::FileParser

Instance Method Details

#generate_hash(output_array) ⇒ Object



57
58
59
60
61
62
63
64
65
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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