BigW Consortium Gitlab

configuration_helper.rb 1.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
module ConfigurationHelper
  # Returns a list of models from hashes/arrays contained in +project_tree+
  def names_from_tree(project_tree)
    project_tree.map do |branch_or_model|
      branch_or_model =  branch_or_model.to_s if branch_or_model.is_a?(Symbol)

      branch_or_model.is_a?(String) ? branch_or_model : names_from_tree(branch_or_model)
    end
  end

  def relation_class_for_name(relation_name)
    relation_name = Gitlab::ImportExport::RelationFactory::OVERRIDES[relation_name.to_sym] || relation_name
    relation_name.to_s.classify.constantize
  end
15 16 17 18 19 20 21 22 23 24

  def parsed_attributes(relation_name, attributes)
    excluded_attributes = config_hash['excluded_attributes'][relation_name]
    included_attributes = config_hash['included_attributes'][relation_name]

    attributes = attributes - JSON[excluded_attributes.to_json] if excluded_attributes
    attributes = attributes & JSON[included_attributes.to_json] if included_attributes

    attributes
  end
25

26 27
  def associations_for(safe_model)
    safe_model.reflect_on_all_associations.map { |assoc| assoc.name.to_s }
28
  end
29
end