Class: Gitlab::PhabricatorImport::Cache::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/phabricator_import/cache/map.rb

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Map

Returns a new instance of Map.


6
7
8
# File 'lib/gitlab/phabricator_import/cache/map.rb', line 6

def initialize(project)
  @project = project
end

Instance Method Details

#get_gitlab_model(phabricator_id) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/phabricator_import/cache/map.rb', line 10

def get_gitlab_model(phabricator_id)
  cached_info = get(phabricator_id)

  if cached_info[:classname] && cached_info[:database_id]
    object = cached_info[:classname].constantize.find_by_id(cached_info[:database_id])
  else
    object = yield if block_given?
    set_gitlab_model(object, phabricator_id) if object
  end

  object
end

#set_gitlab_model(object, phabricator_id) ⇒ Object


23
24
25
# File 'lib/gitlab/phabricator_import/cache/map.rb', line 23

def set_gitlab_model(object, phabricator_id)
  set(object.class, object.id, phabricator_id)
end