Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-09 00:06:02 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-09 00:06:02 +0300
commit8f3b6591ccc1dcebb0e4ae1e3cf44588b2a4afe8 (patch)
treeb470d8784d2e8e13b14a16aa9450a3676d520c33 /lib/gitlab/import/github
parentcb8e9bb6bb0cb3712b888f79d2e8e324724742ad (diff)
Extract base mappergh-refactor
Diffstat (limited to 'lib/gitlab/import/github')
-rw-r--r--lib/gitlab/import/github/mapper/base.rb37
-rw-r--r--lib/gitlab/import/github/mapper/label.rb31
-rw-r--r--lib/gitlab/import/github/mapper/milestone.rb41
3 files changed, 64 insertions, 45 deletions
diff --git a/lib/gitlab/import/github/mapper/base.rb b/lib/gitlab/import/github/mapper/base.rb
new file mode 100644
index 00000000000..78e8b97eb03
--- /dev/null
+++ b/lib/gitlab/import/github/mapper/base.rb
@@ -0,0 +1,37 @@
+module Gitlab
+ module Import
+ module Github
+ module Mapper
+ class Base
+ def initialize(project, client)
+ @project = project
+ @client = client
+ end
+
+ def each
+ return enum_for(:each) unless block_given?
+
+ method = klass.to_s.underscore.pluralize
+
+ client.public_send(method).each do |raw|
+ yield(klass.new(attributes_for(raw)))
+ end
+ end
+
+ private
+
+ attr_reader :project, :client
+
+ def attributes_for
+ {}
+ end
+
+ def klass
+ raise NotImplementedError,
+ "#{self.class} does not implement #{__method__}"
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/import/github/mapper/label.rb b/lib/gitlab/import/github/mapper/label.rb
index 57c0cc35810..4a56a190d18 100644
--- a/lib/gitlab/import/github/mapper/label.rb
+++ b/lib/gitlab/import/github/mapper/label.rb
@@ -2,29 +2,20 @@ module Gitlab
module Import
module Github
module Mapper
- class Label
- def initialize(project, client)
- @project = project
- @client = client
- end
-
- def each
- return enum_for(:each) unless block_given?
-
- client.labels.each do |raw|
- label = ::Label.new(
- project: project,
- title: raw.name,
- color: "##{raw.color}"
- )
+ class Label < Base
+ private
- yield(label)
- end
+ def attributes_for(raw)
+ {
+ project: project,
+ title: raw.name,
+ color: "##{raw.color}"
+ }
end
- private
-
- attr_reader :project, :client
+ def klass
+ ::Label
+ end
end
end
end
diff --git a/lib/gitlab/import/github/mapper/milestone.rb b/lib/gitlab/import/github/mapper/milestone.rb
index a675defdbe9..4d6e8454c55 100644
--- a/lib/gitlab/import/github/mapper/milestone.rb
+++ b/lib/gitlab/import/github/mapper/milestone.rb
@@ -2,34 +2,25 @@ module Gitlab
module Import
module Github
module Mapper
- class Milestone
- def initialize(project, client)
- @project = project
- @client = client
- end
-
- def each
- return enum_for(:each) unless block_given?
-
- client.milestones.each do |raw|
- milestone = ::Milestone.new(
- iid: raw.number,
- project: project,
- title: raw.title,
- description: raw.description,
- due_date: raw.due_on,
- state: raw.state == 'closed' ? 'closed' : 'active',
- created_at: raw.created_at,
- updated_at: raw.state == 'closed' ? raw.closed_at : raw.updated_at
- )
+ class Milestone < Base
+ private
- yield(milestone)
- end
+ def attributes_for(raw)
+ {
+ iid: raw.number,
+ project: project,
+ title: raw.title,
+ description: raw.description,
+ due_date: raw.due_on,
+ state: raw.state == 'closed' ? 'closed' : 'active',
+ created_at: raw.created_at,
+ updated_at: raw.state == 'closed' ? raw.closed_at : raw.updated_at
+ }
end
- private
-
- attr_reader :project, :client
+ def klass
+ ::Milestone
+ end
end
end
end