lib/ncs_navigator/mdes/specification.rb in ncs_mdes-0.11.0 vs lib/ncs_navigator/mdes/specification.rb in ncs_mdes-0.12.0

- old
+ new

@@ -92,14 +92,48 @@ fk_overrides = heuristic_overrides['foreign_keys'][t.name] || { } t.variables.each { |v| v.resolve_foreign_key!(tables, fk_overrides[v.name], :log => @log, :in_table => t) } } + tables.each { |t| t.child_instrument_table = lookup_child_or_parent_table_status(t.name) } } end private :read_transmission_tables + def lookup_child_or_parent_table_status(name) + if child_or_parent_instrument_tables['child_instrument_tables'].include?(name) + true + elsif child_or_parent_instrument_tables['parent_instrument_tables'].include?(name) + false + else + nil + end + end + private :lookup_child_or_parent_table_status + + def child_or_parent_instrument_tables + @child_or_parent_instrument_tables ||= + if source_documents.child_or_parent_instrument_tables + YAML.load(File.read(source_documents.child_or_parent_instrument_tables)).tap do |result| + check_child_or_parent_lists(result) + end + else + Hash.new([]) + end + end + private :child_or_parent_instrument_tables + + def check_child_or_parent_lists(lists) + parent_list = lists['parent_instrument_tables'] + child_list = lists['child_instrument_tables'] + overlap = parent_list & child_list + unless overlap.empty? + @log.warn("These tables appear in both the child instrument and parent instrument lists: #{overlap.inspect}") + end + end + private :check_child_or_parent_lists + ## # A shortcut for accessing particular {#transmission_tables}. # # @overload [](table_name) # Retrieves a single table by name. @@ -160,8 +194,19 @@ # A briefer inspection for nicer IRB sessions. # # @return [String] def inspect "#<#{self.class} version=#{version.inspect}>" + end + + # @private + DIFF_CRITERIA = { + :specification_version => Differences::ValueCriterion.new, + :transmission_tables => Differences::CollectionCriterion.new(:name), + :types => Differences::CollectionCriterion.new(:name) + } + + def diff(other, options={}) + Differences::Entry.compute(self, other, DIFF_CRITERIA, options) end end end