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

to_hash.rb « representation « github_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a0f36ab8f0bf3012b7c0242ff133742b5f1dc0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Representation
      module ToHash
        # Converts the current representation to a Hash. The keys of this Hash
        # will be Symbols.
        def to_hash
          hash = {}

          attributes.each do |key, value|
            hash[key] = convert_value_for_to_hash(value)
          end

          hash
        end

        def convert_value_for_to_hash(value)
          if value.is_a?(Array)
            value.map { |v| convert_value_for_to_hash(v) }
          elsif value.respond_to?(:to_hash)
            value.to_hash
          else
            value
          end
        end
      end
    end
  end
end