Commit efde96e9 authored by James Lopez's avatar James Lopez

started refactored the dynamic rules to be defined in a yml file

parent e05bc611
# Class relationships to be included in the import/export
:project_tree:
- :issues
- :labels
- :milestones
- :snippets
- :releases
- :events
- :project_members:
- :user
- :merge_requests:
- :merge_request_diff
- :commit_statuses:
- :commit
:attributes_only:
:project:
- :name
- :path
- :description
- :issues_enabled
- :wall_enabled
- :merge_requests_enabled
- :wiki_enabled
- :snippets_enabled
- :visibility_level
- :archived
:user:
- :id
- :email
- :username
\ No newline at end of file
module Projects
module ImportExport
module ImportExportReader
extend self
def project_tree
{ only: atts_only[:project], include: build_hash(tree) }
end
def config
@config ||= YAML.load_file('app/services/projects/import_export/import_export.yml')
end
def atts_only
config[:attributes_only]
end
def atts_except
config[:attributes_except]
end
def tree
config[:project_tree]
end
def build_hash(array)
array.map { |el| el.is_a?(Hash) ? process_include(el) : el }
end
def process_include(hash)
included_classes_hash = {}
hash.values.flatten.each do |value|
value = value.is_a?(Hash) ? process_include(hash) : value
new_hash = { :include => value }
new_hash.merge!(check_only(value))
included_classes_hash[hash.keys.first] = new_hash
end
included_classes_hash
end
def check_only(value)
key = value.is_a?(Hash) ? value.keys.first : value
atts_only[key].nil? ? {} : { only: atts_only[key] }
end
end
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment