Class: Gitlab::Git::User

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, name, email, gl_id, timezone) ⇒ User

Returns a new instance of User.


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/git/user.rb', line 22

def initialize(username, name, email, gl_id, timezone)
  @username = username
  @name = name
  @email = email
  @gl_id = gl_id

  @timezone = if Feature.enabled?(:add_timezone_to_web_operations)
                timezone
              else
                Time.zone.tzinfo.name
              end
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.


6
7
8
# File 'lib/gitlab/git/user.rb', line 6

def email
  @email
end

#gl_idObject (readonly)

Returns the value of attribute gl_id.


6
7
8
# File 'lib/gitlab/git/user.rb', line 6

def gl_id
  @gl_id
end

#nameObject (readonly)

Returns the value of attribute name.


6
7
8
# File 'lib/gitlab/git/user.rb', line 6

def name
  @name
end

#timezoneObject (readonly)

Returns the value of attribute timezone.


6
7
8
# File 'lib/gitlab/git/user.rb', line 6

def timezone
  @timezone
end

#usernameObject (readonly)

Returns the value of attribute username.


6
7
8
# File 'lib/gitlab/git/user.rb', line 6

def username
  @username
end

Class Method Details

.from_gitaly(gitaly_user) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/git/user.rb', line 12

def self.from_gitaly(gitaly_user)
  new(
    gitaly_user.gl_username,
    Gitlab::EncodingHelper.encode!(gitaly_user.name),
    Gitlab::EncodingHelper.encode!(gitaly_user.email),
    gitaly_user.gl_id,
    gitaly_user.timezone
  )
end

.from_gitlab(gitlab_user) ⇒ Object


8
9
10
# File 'lib/gitlab/git/user.rb', line 8

def self.from_gitlab(gitlab_user)
  new(gitlab_user.username, gitlab_user.name, gitlab_user.commit_email_or_default, Gitlab::GlId.gl_id(gitlab_user), gitlab_user.timezone)
end

Instance Method Details

#==(other) ⇒ Object


35
36
37
# File 'lib/gitlab/git/user.rb', line 35

def ==(other)
  [username, name, email, gl_id, timezone] == [other.username, other.name, other.email, other.gl_id, other.timezone]
end

#to_gitalyObject


39
40
41
# File 'lib/gitlab/git/user.rb', line 39

def to_gitaly
  Gitaly::User.new(gl_username: username, gl_id: gl_id, name: name.b, email: email.b, timezone: timezone)
end